2022-10-12 09:59:00 +00:00
|
|
|
From fe0ce4764ce3839f8019a2b0ecfc1d41c87595c6 Mon Sep 17 00:00:00 2001
|
|
|
|
From: =?UTF-8?q?Fridrich=20=C5=A0trba?= <fridrich.strba@bluewin.ch>
|
|
|
|
Date: Wed, 12 Oct 2022 10:58:47 +0200
|
|
|
|
Subject: [PATCH 2/3] Replace bundled gdata-java-client classes with
|
2019-11-10 19:33:42 +00:00
|
|
|
commons-codec
|
|
|
|
|
|
|
|
---
|
2022-10-12 09:59:00 +00:00
|
|
|
.../org/yaml/snakeyaml/util/UriEncoder.java | 37 +++++++++++++++----
|
|
|
|
1 file changed, 29 insertions(+), 8 deletions(-)
|
2019-11-10 19:33:42 +00:00
|
|
|
|
|
|
|
diff --git a/src/main/java/org/yaml/snakeyaml/util/UriEncoder.java b/src/main/java/org/yaml/snakeyaml/util/UriEncoder.java
|
2022-10-12 09:59:00 +00:00
|
|
|
index 02c3e434..f6b5a639 100644
|
2019-11-10 19:33:42 +00:00
|
|
|
--- a/src/main/java/org/yaml/snakeyaml/util/UriEncoder.java
|
|
|
|
+++ b/src/main/java/org/yaml/snakeyaml/util/UriEncoder.java
|
2022-10-12 09:59:00 +00:00
|
|
|
@@ -22,18 +22,33 @@ import java.nio.charset.CharsetDecoder;
|
2019-11-10 19:33:42 +00:00
|
|
|
import java.nio.charset.CodingErrorAction;
|
2022-10-12 09:59:00 +00:00
|
|
|
import java.nio.charset.StandardCharsets;
|
2019-11-10 19:33:42 +00:00
|
|
|
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;
|
2022-10-12 09:59:00 +00:00
|
|
|
+import java.util.BitSet;
|
|
|
|
+
|
|
|
|
+import org.apache.commons.codec.net.URLCodec;
|
2019-11-10 19:33:42 +00:00
|
|
|
|
|
|
|
public abstract class UriEncoder {
|
|
|
|
|
2022-10-12 09:59:00 +00:00
|
|
|
+ // 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/
|
|
|
|
+ for (char c : "-_.!~*'()@:$&,;=/[]".toCharArray()) {
|
|
|
|
+ allowedCharacters.set(c);
|
|
|
|
+ }
|
|
|
|
+ }
|
2019-11-10 19:33:42 +00:00
|
|
|
+
|
2022-10-12 09:59:00 +00:00
|
|
|
private static final CharsetDecoder UTF8Decoder =
|
|
|
|
StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT);
|
|
|
|
- // Include the [] chars to the SAFEPATHCHARS_URLENCODER to avoid
|
|
|
|
- // its escape as required by spec. See
|
|
|
|
- // 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);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Escape special characters with '%'
|
|
|
|
@@ -42,7 +57,13 @@ public abstract class UriEncoder {
|
|
|
|
* @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);
|
|
|
|
+ }
|
|
|
|
}
|
2019-11-10 19:33:42 +00:00
|
|
|
|
2022-10-12 09:59:00 +00:00
|
|
|
/**
|
2019-11-10 19:33:42 +00:00
|
|
|
--
|
2022-09-06 13:54:49 +00:00
|
|
|
2.37.3
|
2019-11-10 19:33:42 +00:00
|
|
|
|