Skip to content

Commit

Permalink
Add a passing test wrt FasterXML/jackson-core#586
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed May 4, 2020
1 parent 275275a commit b83ab88
Showing 1 changed file with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testSimpleAltSources() throws Exception
assertEquals(1, ((List<?>) ob).size());
}

public void testParserFeatures() throws Exception
public void testParserFeaturesComments() throws Exception
{
final String JSON = "[ /* foo */ 7 ]";
// default won't accept comments, let's change that:
Expand All @@ -71,6 +71,36 @@ public void testParserFeatures() throws Exception
}
}

public void testParserFeaturesCtrlChars() throws Exception
{
String FIELD = "a\tb";
String VALUE = "\t";
String JSON = "{ "+quote(FIELD)+" : "+quote(VALUE)+"}";
Map<?, ?> result;

// First: by default, unescaped control characters should not work
try {
result = MAPPER.readValue(JSON, Map.class);
fail("Should not pass with defaylt settings");
} catch (JsonParseException e) {
verifyException(e, "Illegal unquoted character");
}

// But both ObjectReader:
result = MAPPER.readerFor(Map.class)
.with(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS)
.readValue(JSON);
assertEquals(1, result.size());

// and new mapper should work
ObjectMapper mapper2 = JsonMapper.builder()
.enable(JsonReadFeature.ALLOW_UNESCAPED_CONTROL_CHARS)
.build();
result = mapper2.readerFor(Map.class)
.readValue(JSON);
assertEquals(1, result.size());
}

public void testNodeHandling() throws Exception
{
JsonNodeFactory nodes = new JsonNodeFactory(true);
Expand Down

0 comments on commit b83ab88

Please sign in to comment.