Test escaping HTML characters!
This commit is contained in:
parent
486820f515
commit
78d1011ec5
@ -19,7 +19,8 @@ package com.google.gson.functional;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.common.TestTypes.BagOfPrimitives;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
@ -45,6 +46,18 @@ public class EscapingTest extends TestCase {
|
||||
assertEquals(valueWithQuotes[0], target[0]);
|
||||
}
|
||||
|
||||
public void testEscapeAllHtmlCharacters() {
|
||||
List<String> strings = new ArrayList<String>();
|
||||
strings.add("<");
|
||||
strings.add(">");
|
||||
strings.add("=");
|
||||
strings.add("&");
|
||||
strings.add("'");
|
||||
strings.add("\"");
|
||||
assertEquals("[\"\\u003c\",\"\\u003e\",\"\\u003d\",\"\\u0026\",\"'\",\"\\\"\"]",
|
||||
gson.toJson(strings));
|
||||
}
|
||||
|
||||
public void testEscapingObjectFields() throws Exception {
|
||||
BagOfPrimitives objWithPrimitives = new BagOfPrimitives(1L, 1, true, "test with\" <script>");
|
||||
String jsonRepresentation = gson.toJson(objWithPrimitives);
|
||||
|
Loading…
Reference in New Issue
Block a user