From e0195fcc5449238fb5dafedfb6f60217234a5432 Mon Sep 17 00:00:00 2001 From: Inderjeet Singh Date: Tue, 23 Dec 2008 18:18:14 +0000 Subject: [PATCH] code review changes from r342 Enabled escaping of / --- gson/src/main/java/com/google/gson/Escaper.java | 4 ++-- .../com/google/gson/functional/DefaultTypeAdaptersTest.java | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gson/src/main/java/com/google/gson/Escaper.java b/gson/src/main/java/com/google/gson/Escaper.java index bed7278e..bb880a20 100644 --- a/gson/src/main/java/com/google/gson/Escaper.java +++ b/gson/src/main/java/com/google/gson/Escaper.java @@ -56,6 +56,7 @@ class Escaper { tmpSet.add('>'); tmpSet.add('&'); tmpSet.add('='); + tmpSet.add('/'); tmpSet.add('\\'); JS_ESCAPE_CHARS = Collections.unmodifiableSet(tmpSet); } @@ -77,8 +78,7 @@ class Escaper { int codePoint = Character.codePointAt(plainText, i); charCount = Character.charCount(codePoint); - if (!(isControlCharacter(codePoint) - || mustEscapeCharInJsString(codePoint))) { + if (!isControlCharacter(codePoint) && !mustEscapeCharInJsString(codePoint)) { continue; } diff --git a/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java b/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java index 695c1dfe..9f78a41a 100644 --- a/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java +++ b/gson/src/test/java/com/google/gson/functional/DefaultTypeAdaptersTest.java @@ -52,12 +52,12 @@ public class DefaultTypeAdaptersTest extends TestCase { public void testUrlSerialization() throws Exception { String urlValue = "http://google.com/"; URL url = new URL(urlValue); - assertEquals('"' + urlValue + '"', gson.toJson(url)); + assertEquals("\"http:\\/\\/google.com\\/\"", gson.toJson(url)); } public void testUrlDeserialization() { String urlValue = "http://google.com/"; - String json = '"' + urlValue + '"'; + String json = "'http:\\/\\/google.com\\/'"; URL target = gson.fromJson(json, URL.class); assertEquals(urlValue, target.toExternalForm()); } @@ -80,7 +80,7 @@ public class DefaultTypeAdaptersTest extends TestCase { public void testUriSerialization() throws Exception { String uriValue = "http://google.com/"; URI uri = new URI(uriValue); - assertEquals('"' + uriValue + '"', gson.toJson(uri)); + assertEquals("\"http:\\/\\/google.com\\/\"", gson.toJson(uri)); } public void testUriDeserialization() {