import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.gson.stream.JsonWriter;
-import java.io.IOException;
-import java.io.Writer;
-import java.net.URI;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import java.io.IOException;
+import java.io.Writer;
+import java.net.URI;
+
/**
* This implementation will create JSON output as output stream.
*
/**
* Matcher used to check if a string needs to be escaped.
*/
- private static final CharMatcher QUOTES_OR_BACKSLASH = CharMatcher.anyOf("\\\"");
+ private static final CharMatcher JSON_ILLEGAL_STRING_CHARACTERS = CharMatcher.anyOf("\\\"\n\r");
private final SchemaTracker tracker;
private final JSONCodecFactory codecs;
if (needQuotes) {
writer.append('"');
- final int needEscape = QUOTES_OR_BACKSLASH.countIn(str);
+ final int needEscape = JSON_ILLEGAL_STRING_CHARACTERS.countIn(str);
if (needEscape != 0) {
final char[] escaped = new char[str.length() + needEscape];
int offset = 0;
for (int i = 0; i < str.length(); i++) {
final char c = str.charAt(i);
- if (QUOTES_OR_BACKSLASH.matches(c)) {
+ if (JSON_ILLEGAL_STRING_CHARACTERS.matches(c)) {
escaped[offset++] = '\\';
}
escaped[offset++] = c;