oblac / jodd

Jodd! Lightweight. Java. Zero dependencies. Use what you like.

Home Page:https://jodd.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Lazy JsonParser crash on escaped double quote

slandelle opened this issue · comments

Current behavior

{	
	"values": [
		{
			"value": "foo\"bar"
		}
	]
}
JsonParser.createLazyOne().parse(STRING);
Exception in thread "main" jodd.json.JsonException: Syntax error! End of JSON
offset: 59 near: "...}
	]
}
"
	at jodd.json.JsonParser.syntaxError(JsonParser.java:1197)
	at jodd.json.JsonParser._parse(JsonParser.java:382)
	at jodd.json.JsonParser.parse(JsonParser.java:348)

Expected behavior

Syntax is perfectly valid

Steps to Reproduce the Problem

see above.

Note that issue doesn't happen with the eager default parser.

Here's a reproducer to be added in JsonParserTest:

	@Test
	void testLazyParserSupportEscapedDoubleQuotes() {
		String json = "{ \"values\": [{ \"value\": \"foo\\\"bar\" }]}";

		JsonParsers.forEachParser(jsonParser -> {
			Map<String, String> object = jsonParser.parse(json);

			List<Map.Entry<String, String>> entries = object.entrySet().stream().collect(Collectors.toList());

			assertEquals(1, entries.size());
			assertEquals("values", entries.get(0).getKey());
		});
	}

PR under way.

@igr PR sent: #638 PTAL :)

@slandelle released :)

Thanks a lot, man!