Stop pretty printing from truncating content starts as valid JSON

Fixes gh-730
This commit is contained in:
Andy Wilkinson
2021-06-15 11:37:29 +01:00
parent f3e305ab24
commit 88fe8a6f13
2 changed files with 11 additions and 3 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2019 the original author or authors.
* Copyright 2014-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +34,7 @@ import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stream.StreamResult;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.xml.sax.ErrorHandler;
@@ -140,8 +141,8 @@ public class PrettyPrintingContentModifier implements ContentModifier {
private static final class JsonPrettyPrinter implements PrettyPrinter {
private final ObjectMapper objectMapper = new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT,
true);
private final ObjectMapper objectMapper = new ObjectMapper().configure(SerializationFeature.INDENT_OUTPUT, true)
.configure(DeserializationFeature.FAIL_ON_TRAILING_TOKENS, true);
@Override
public byte[] prettyPrint(byte[] original) throws IOException {

View File

@@ -64,7 +64,14 @@ public class PrettyPrintingContentModifierTests {
this.outputCapture.expect(isEmptyString());
assertThat(new PrettyPrintingContentModifier().modifyContent(content.getBytes(), null))
.isEqualTo(content.getBytes());
}
@Test
public void nonJsonContentThatInitiallyLooksLikeJsonIsHandledGracefully() throws Exception {
String content = "\"abc\",\"def\"";
this.outputCapture.expect(isEmptyString());
assertThat(new PrettyPrintingContentModifier().modifyContent(content.getBytes(), null))
.isEqualTo(content.getBytes());
}
@Test