summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriwakeh <iwakeh@torproject.org>2018-04-06 09:53:35 +0000
committeriwakeh <iwakeh@torproject.org>2018-04-06 09:53:36 +0000
commita742b9427a468314882fd5cf97c770cacbe1c9e6 (patch)
treef1f5e4afc65879250eec44969e755e79bdff1f34
parent1d874ba10dbc8ba82795e370941bed8eef71746d (diff)
Provide utf-characters instead of escape strings.task-25740
Also adapt tests to check the new functionality. Implements task-25740.
-rw-r--r--src/main/java/org/torproject/onionoo/util/FormattingUtils.java6
-rw-r--r--src/test/resources/lines-for-escape-tests.txt26
2 files changed, 20 insertions, 12 deletions
diff --git a/src/main/java/org/torproject/onionoo/util/FormattingUtils.java b/src/main/java/org/torproject/onionoo/util/FormattingUtils.java
index 3d16f5a..558477d 100644
--- a/src/main/java/org/torproject/onionoo/util/FormattingUtils.java
+++ b/src/main/java/org/torproject/onionoo/util/FormattingUtils.java
@@ -3,6 +3,8 @@
package org.torproject.onionoo.util;
+import static org.apache.commons.lang3.StringEscapeUtils.unescapeJava;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -58,8 +60,8 @@ public class FormattingUtils {
StringBuffer sb = new StringBuffer();
Matcher mat = escapePattern.matcher(text);
while (mat.find()) {
- String unescaped = mat.group(1);
- mat.appendReplacement(sb, unescaped);
+ String unescaped = mat.group(1).substring(1);
+ mat.appendReplacement(sb, unescapeJava(unescaped));
}
mat.appendTail(sb);
return sb.toString();
diff --git a/src/test/resources/lines-for-escape-tests.txt b/src/test/resources/lines-for-escape-tests.txt
index 4fb5895..b08b723 100644
--- a/src/test/resources/lines-for-escape-tests.txt
+++ b/src/test/resources/lines-for-escape-tests.txt
@@ -2,15 +2,21 @@
abc
abc
-\\\\u
-\\\\u
+\\\\u00bb \\\\u \\\\u00ab
+» \\\\u «
Haha/\\\\@/\\\\live/\\\\./\\\\co/\\\\./\\\uk
Haha/\\\\@/\\\\live/\\\\./\\\\co/\\\\./\\\uk
-\\\\u20ac
-\\u20ac
-\\\\u0024
-\\u0024
-some \\\\u20ac other string \\\\u0024 to unescape
-some \\u20ac other string \\u0024 to unescape
-abcd efg\\\\u0024xyz\\\\uxxxx
-abcd efg\\u0024xyz\\\\uxxxx
+Euro \\\\u20ac
+Euro €
+Dollar \\\\u0024
+Dollar $
+Pound \\\\u00a3
+Pound £
+Yen \\\\u00a5
+Yen ¥
+\\\\u00a1some \\\\u00dE other string \\\\u00e7 to unescape!
+¡some Þ other string ç to unescape!
+abcd efg cent \\\\u00a2xyz\\\\uxxxx
+abcd efg cent ¢xyz\\\\uxxxx
+Telef\\\\u00F4nica
+Telefônica