[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [onionoo/master] Don't escape `/` before feeding strings into Gson.



commit 1b3a455719e333764b76aa012e51674b6f7e1c56
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Wed Feb 25 12:03:26 2015 +0100

    Don't escape `/` before feeding strings into Gson.
    
    We escape a few characters in strings before feeding them into Gson,
    including backslashes, double quotes, \b, \n, \t, \f, \r, and non-ASCII
    characters.  But we also escape `/` to `\/` which we did not change back
    after receiving Gson's output.  We should simply stop escaping forward
    slashes, because Gson leaves them untouched.  The easiest way to change
    this is to switch from escapeEcmaScript to escapeJava which also saves us
    the effort of undoing the escaping of `'`.
    
    Fixes #13267.
---
 src/main/java/org/torproject/onionoo/docs/DetailsDocument.java |    7 ++-----
 src/main/java/org/torproject/onionoo/docs/DetailsStatus.java   |    7 ++-----
 2 files changed, 4 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java b/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java
index 99a98cb..d4efdc0 100644
--- a/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java
+++ b/src/main/java/org/torproject/onionoo/docs/DetailsDocument.java
@@ -8,7 +8,6 @@ import java.util.Map;
 import java.util.SortedSet;
 
 import org.apache.commons.lang3.StringEscapeUtils;
-import org.apache.commons.lang3.StringUtils;
 
 public class DetailsDocument extends Document {
 
@@ -21,12 +20,10 @@ public class DetailsDocument extends Document {
    * we'll have to do is to change back the '\\' that Gson writes for the
    * '\'. */
   private static String escapeJSON(String s) {
-    return StringUtils.replaceEach(StringEscapeUtils.escapeEcmaScript(s),
-        new String[] { "\\'" }, new String[] { "'" });
+    return StringEscapeUtils.escapeJava(s);
   }
   private static String unescapeJSON(String s) {
-    return StringEscapeUtils.unescapeEcmaScript(StringUtils.replaceEach(s,
-        new String[] { "'" }, new String[] { "\\'" }));
+    return StringEscapeUtils.unescapeJava(s);
   }
 
   private String nickname;
diff --git a/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java b/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java
index ff951ce..fe46416 100644
--- a/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java
+++ b/src/main/java/org/torproject/onionoo/docs/DetailsStatus.java
@@ -8,7 +8,6 @@ import java.util.SortedSet;
 import java.util.TreeSet;
 
 import org.apache.commons.lang3.StringEscapeUtils;
-import org.apache.commons.lang3.StringUtils;
 
 public class DetailsStatus extends Document {
 
@@ -21,12 +20,10 @@ public class DetailsStatus extends Document {
    * we'll have to do is to change back the '\\' that Gson writes for the
    * '\'. */
   private static String escapeJSON(String s) {
-    return StringUtils.replaceEach(StringEscapeUtils.escapeEcmaScript(s),
-        new String[] { "\\'" }, new String[] { "'" });
+    return StringEscapeUtils.escapeJava(s);
   }
   private static String unescapeJSON(String s) {
-    return StringEscapeUtils.unescapeEcmaScript(StringUtils.replaceEach(s,
-        new String[] { "'" }, new String[] { "\\'" }));
+    return StringEscapeUtils.unescapeJava(s);
   }
 
   /* From most recently published server descriptor: */

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits