58 lines
2.2 KiB
Diff
58 lines
2.2 KiB
Diff
--- asomov-snakeyaml-8450addf3473/src/main/java/org/yaml/snakeyaml/util/UriEncoder.java 2019-08-13 21:16:33.000000000 +0200
|
|
+++ asomov-snakeyaml-8450addf3473/src/main/java/org/yaml/snakeyaml/util/UriEncoder.java 2019-11-09 19:52:54.807790865 +0100
|
|
@@ -23,19 +23,33 @@
|
|
import java.nio.charset.Charset;
|
|
import java.nio.charset.CharsetDecoder;
|
|
import java.nio.charset.CodingErrorAction;
|
|
+import java.util.BitSet;
|
|
|
|
+import org.apache.commons.codec.net.URLCodec;
|
|
import org.yaml.snakeyaml.error.YAMLException;
|
|
-import org.yaml.snakeyaml.external.com.google.gdata.util.common.base.Escaper;
|
|
-import org.yaml.snakeyaml.external.com.google.gdata.util.common.base.PercentEscaper;
|
|
|
|
public abstract class UriEncoder {
|
|
private static final CharsetDecoder UTF8Decoder = Charset.forName("UTF-8").newDecoder()
|
|
.onMalformedInput(CodingErrorAction.REPORT);
|
|
- // Include the [] chars to the SAFEPATHCHARS_URLENCODER to avoid
|
|
- // its escape as required by spec. See
|
|
+
|
|
+ // default safe characters which can appear within URI and shouldn't be escaped
|
|
+ private static final BitSet allowedCharacters = new BitSet(256);
|
|
+
|
|
+ static {
|
|
+ for (int i = 'a'; i <= 'z'; i++) {
|
|
+ allowedCharacters.set(i);
|
|
+ }
|
|
+ for (int i = 'A'; i <= 'Z'; i++) {
|
|
+ allowedCharacters.set(i);
|
|
+ }
|
|
+ for (int i = '0'; i <= '9'; i++) {
|
|
+ allowedCharacters.set(i);
|
|
+ }
|
|
// http://yaml.org/spec/1.1/#escaping%20in%20URI/
|
|
- private static final String SAFE_CHARS = PercentEscaper.SAFEPATHCHARS_URLENCODER + "[]/";
|
|
- private static final Escaper escaper = new PercentEscaper(SAFE_CHARS, false);
|
|
+ for (char c : "-_.!~*'()@:$&,;=/[]".toCharArray()) {
|
|
+ allowedCharacters.set(c);
|
|
+ }
|
|
+ }
|
|
|
|
/**
|
|
* Escape special characters with '%'
|
|
@@ -43,7 +57,13 @@
|
|
* @return encoded URI
|
|
*/
|
|
public static String encode(String uri) {
|
|
- return escaper.escape(uri);
|
|
+ try {
|
|
+ byte[] rawdata = URLCodec.encodeUrl(allowedCharacters,
|
|
+ uri.getBytes("UTF-8"));
|
|
+ return new String(rawdata, 0, rawdata.length, "US-ASCII");
|
|
+ } catch (UnsupportedEncodingException e) {
|
|
+ throw new YAMLException(e);
|
|
+ }
|
|
}
|
|
|
|
/**
|