You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ma...@apache.org on 2022/03/30 00:27:11 UTC
[logging-log4j2] branch master updated: Add more JsonReader comment parsing tests
This is an automated email from the ASF dual-hosted git repository.
mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git
The following commit(s) were added to refs/heads/master by this push:
new e03f183 Add more JsonReader comment parsing tests
e03f183 is described below
commit e03f1832ed0791e5c489a65983de9ee707145ccd
Author: Matt Sicker <ma...@apache.org>
AuthorDate: Tue Mar 29 19:26:59 2022 -0500
Add more JsonReader comment parsing tests
Signed-off-by: Matt Sicker <ma...@apache.org>
---
.../logging/log4j/core/util/JsonReaderTest.java | 39 ++++++++++++++++++++--
1 file changed, 37 insertions(+), 2 deletions(-)
diff --git a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/JsonReaderTest.java b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/JsonReaderTest.java
index 0c5a4bd..5da2820 100644
--- a/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/JsonReaderTest.java
+++ b/log4j-core-test/src/test/java/org/apache/logging/log4j/core/util/JsonReaderTest.java
@@ -18,6 +18,8 @@ package org.apache.logging.log4j.core.util;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -376,9 +378,42 @@ class JsonReaderTest {
}})));
}
+ @ParameterizedTest
+ @ValueSource(strings = {
+ "/*comment*/{\"foo\":\"bar\"}",
+ "{/*comment*/\"foo\":\"bar\"}",
+ "{\"foo\"/*comment*/:\"bar\"}",
+ "{\"foo\":/*comment*/\"bar\"}",
+ "{\"foo\":\"bar\"/*comment*/}",
+ "{\"foo\":\"bar\"}/*comment*/",
+ "/*\nmulti\nline\ncomment\n*/{\"foo\":\"bar\"}/*comment*/",
+ "{\"foo\"/*comment*/:/*comment*/\"bar\"}",
+ "{\"foo\"/*:*/:/*\"*/\"bar\"}",
+ "{\"foo\"/*\nanother comment*/:\"bar\"}",
+ "{\"foo\":\"bar\"/*\n}{}*/}",
+ })
+ void test_comments(final String json) {
+ test(json, Map.of("foo", "bar"));
+ }
+
+ @Test
+ void test_unclosed_comments_error() {
+ final String json = "{\"foo\": /*";
+ Assertions
+ .assertThatThrownBy(() -> JsonReader.read(json))
+ .as("json=%s", json)
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("premature end of input");
+ }
+
@Test
- void test_comments() {
- test("/*comment1*/{\"foo\": /* comment two */\"bar\"}", Map.of("foo", "bar"));
+ void test_unopened_comments_error() {
+ final String json = "{\"foo\": */";
+ Assertions
+ .assertThatThrownBy(() -> JsonReader.read(json))
+ .as("json=%s", json)
+ .isInstanceOf(IllegalArgumentException.class)
+ .hasMessage("invalid character at index 8: *");
}
private void test(final String json, final Object expected) {