• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.fasterxml.jackson.databind.util;
2 
3 import java.io.IOException;
4 
5 import com.fasterxml.jackson.databind.BaseMapTest;
6 import com.fasterxml.jackson.databind.ObjectMapper;
7 
8 public class JSONPObjectTest extends BaseMapTest {
9 
10   private final String CALLBACK = "callback";
11   private final ObjectMapper MAPPER = new ObjectMapper();
12 
13   /**
14    * Unit tests for checking that JSONP breaking characters U+2028 and U+2029 are escaped when creating a {@link JSONPObject}.
15    */
16 
testU2028Escaped()17   public void testU2028Escaped() throws IOException {
18     String containsU2028 = String.format("This string contains %c char", '\u2028');
19     JSONPObject jsonpObject = new JSONPObject(CALLBACK, containsU2028);
20     String valueAsString = MAPPER.writeValueAsString(jsonpObject);
21     assertFalse(valueAsString.contains("\u2028"));
22   }
23 
testU2029Escaped()24   public void testU2029Escaped() throws IOException {
25     String containsU2029 = String.format("This string contains %c char", '\u2029');
26     JSONPObject jsonpObject = new JSONPObject(CALLBACK, containsU2029);
27     String valueAsString = MAPPER.writeValueAsString(jsonpObject);
28     assertFalse(valueAsString.contains("\u2029"));
29   }
30 
testU2030NotEscaped()31   public void testU2030NotEscaped() throws IOException {
32     String containsU2030 = String.format("This string contains %c char", '\u2030');
33     JSONPObject jsonpObject = new JSONPObject(CALLBACK, containsU2030);
34     String valueAsString = MAPPER.writeValueAsString(jsonpObject);
35     assertTrue(valueAsString.contains("\u2030"));
36   }
37 }
38