Skip to content

Commit

Permalink
Merge branch '2.19'
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jan 12, 2025
2 parents f0412af + de01c68 commit f9a5ef3
Show file tree
Hide file tree
Showing 15 changed files with 435 additions and 425 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.*;
import java.util.Arrays;

import tools.jackson.core.*;
Expand Down
20 changes: 7 additions & 13 deletions toml/src/main/java/tools/jackson/dataformat/toml/TomlParser.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
package tools.jackson.dataformat.toml;

import java.io.IOException;
import java.io.Reader;
import java.math.BigDecimal;
import java.time.*;
import java.time.temporal.Temporal;

import tools.jackson.core.io.IOContext;
import tools.jackson.core.io.NumberInput;
import tools.jackson.core.StreamReadFeature;
import tools.jackson.core.exc.StreamConstraintsException;
import tools.jackson.core.util.VersionUtil;
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.node.ArrayNode;
import tools.jackson.databind.node.JsonNodeFactory;
import tools.jackson.databind.node.ObjectNode;
import tools.jackson.databind.node.ValueNode;

import java.io.IOException;
import java.io.Reader;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.temporal.Temporal;
import tools.jackson.databind.node.*;

class TomlParser {
private static final JsonNodeFactory factory = new JsonNodeFactoryImpl();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package tools.jackson.dataformat.toml;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import tools.jackson.databind.ObjectMapper;

import static org.junit.jupiter.api.Assertions.*;

// Copied from YAML modules "DatabindAdvancedTest"
public class ComplexPojoReadWriteTest extends TomlMapperTestBase
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,19 @@
package tools.jackson.dataformat.toml;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Collection;
import java.util.Collections;
import java.util.stream.Collectors;
import java.nio.file.*;
import java.util.stream.Stream;

import tools.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import tools.jackson.databind.ObjectMapper;

@RunWith(Parameterized.class)
public class ComplianceInvalidTest extends TomlMapperTestBase {
@Parameterized.Parameters
public static Collection<Object[]> data() throws IOException {
Path folder = Paths.get("compliance", "invalid");
if (!Files.exists(folder)) {
return Collections.emptyList();
}
return Files.walk(folder)
.filter(Files::isRegularFile)
.map(p -> new Object[]{p})
.collect(Collectors.toList());
}
import static org.junit.jupiter.api.Assertions.assertThrows;

public class ComplianceInvalidTest extends TomlMapperTestBase
{
private final ObjectMapper MAPPER = newTomlMapper();

private final Path path;
Expand All @@ -36,9 +22,29 @@ public ComplianceInvalidTest(Path path) {
this.path = path;
}

@Test(expected = TomlStreamReadException.class)
public void test() throws IOException {
// TODO: verify more details of failure
MAPPER.readTree(path.toFile());
// JUnit 5 throws error when methodSource provides empty `Stream` which
// seems to always be the case....
@Disabled
@MethodSource("data")
@ParameterizedTest
public void test(Path path) throws IOException {
// Test implementation
ObjectMapper MAPPER = newTomlMapper();
assertThrows(
TomlStreamReadException.class,
() -> MAPPER.readTree(path.toFile())
);
}

// This is the static method that provides data for the parameterized test
public static Stream<Object[]> data() throws IOException {
Path folder = Paths.get("compliance", "invalid");
if (!Files.exists(folder)) {
return Stream.empty(); // Ensure this folder exists with files for the test to run
}
return Files.walk(folder)
.filter(Files::isRegularFile)
.map(p -> new Object[]{p});
}

}
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package tools.jackson.dataformat.toml;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.util.Collection;
import java.util.Collections;
import java.nio.file.*;
import java.time.*;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import tools.jackson.core.io.NumberInput;
import tools.jackson.databind.JsonNode;
Expand All @@ -21,18 +18,14 @@
import tools.jackson.databind.node.JsonNodeCreator;
import tools.jackson.databind.node.ObjectNode;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import static org.junit.jupiter.api.Assertions.assertEquals;

@RunWith(Parameterized.class)
public class ComplianceValidTest extends TomlMapperTestBase {
@Parameterized.Parameters
public static Collection<Object[]> data() throws IOException {
public class ComplianceValidTest extends TomlMapperTestBase
{
public static Stream<Object[]> data() throws IOException {
Path folder = Paths.get("compliance", "valid");
if (!Files.exists(folder)) {
return Collections.emptyList();
return Stream.empty();
}
return Files.walk(folder)
.filter(Files::isRegularFile)
Expand All @@ -53,8 +46,7 @@ public static Collection<Object[]> data() throws IOException {
*/
return null;
})
.filter(Objects::nonNull)
.collect(Collectors.toList());
.filter(Objects::nonNull);
}

private final Path path;
Expand All @@ -65,12 +57,16 @@ public ComplianceValidTest(Path path, ObjectNode expected) {
this.expected = expected;
}

@Test
public void test() {
// JUnit 5 throws error when methodSource provides empty `Stream` which
// seems to always be the case....
@Disabled
@MethodSource("data")
@ParameterizedTest
public void test() throws Exception {
JsonNode actual = TomlMapper.builder()
.enable(TomlReadFeature.PARSE_JAVA_TIME)
.build().readTree(path);
Assert.assertEquals(mapFromComplianceNode(expected), actual);
.build().readTree(path.toFile());
assertEquals(mapFromComplianceNode(expected), actual);
}

private static JsonNode mapFromComplianceNode(ObjectNode expected) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
import java.io.InputStream;
import java.util.Arrays;

import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import tools.jackson.core.exc.StreamReadException;

import tools.jackson.databind.ObjectMapper;

import static org.junit.jupiter.api.Assertions.fail;

/**
* Collection of OSS-Fuzz found issues for TOML format module.
*/
Expand All @@ -25,7 +26,7 @@ public void testArrayCopy57237() throws Exception
"/clusterfuzz-testcase-minimized-TOMLFuzzer-6542204348006400")) {
try {
TOML_MAPPER.readTree(is);
Assert.fail("Should not pass");
fail("Should not pass");
} catch (StreamReadException e) {
// Possibly not what we should get; tweak once working
verifyException(e, "Premature end of file");
Expand All @@ -43,6 +44,6 @@ protected void verifyException(Throwable e, String... matches)
return;
}
}
Assert.fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.InputStream;
import java.util.Arrays;

import org.junit.jupiter.api.Test;

import tools.jackson.core.JacksonException;
import tools.jackson.core.StreamReadConstraints;
import tools.jackson.core.StreamWriteConstraints;
Expand All @@ -11,9 +13,7 @@
import tools.jackson.databind.JsonNode;
import tools.jackson.databind.ObjectMapper;

import org.junit.Assert;
import org.junit.Test;

import static org.junit.jupiter.api.Assertions.fail;
/**
* Collection of OSS-Fuzz found issues for TOML format module.
*/
Expand All @@ -31,7 +31,7 @@ public void testBigIntegerDecoding50033() throws Exception
;
try {
JsonNode n = TOML_MAPPER.readTree(INPUT);
Assert.fail("Should not pass, got: "+n);
fail("Should not pass, got: "+n);
} catch (StreamReadException e) {
verifyException(e, "Premature end of file");
// NOTE: decoding of token for error message seems wrong, cannot
Expand All @@ -46,7 +46,7 @@ public void testUTF8Decoding50036() throws Exception
byte[] INPUT = new byte[] { 0x20, (byte) 0xCD };
try {
TOML_MAPPER.readTree(INPUT);
Assert.fail("Should not pass");
fail("Should not pass");
} catch (JacksonException e) {
verifyException(e, "End-of-input after first 1 byte");
verifyException(e, "of a UTF-8 character");
Expand All @@ -61,7 +61,7 @@ public void testParseInlineTable50432() throws Exception
"/clusterfuzz-testcase-minimized-TOMLFuzzer-6370486359031808")) {
try {
TOML_MAPPER.readTree(is);
Assert.fail("Should not pass");
fail("Should not pass");
} catch (StreamConstraintsException e) {
String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed",
StreamReadConstraints.DEFAULT_MAX_DEPTH + 1);
Expand All @@ -78,7 +78,7 @@ public void testCodepoint51654() throws Exception
"/clusterfuzz-testcase-minimized-TOMLFuzzer-5068015447703552")) {
try {
TOML_MAPPER.readTree(is);
Assert.fail("Should not pass");
fail("Should not pass");
} catch (StreamReadException e) {
verifyException(e, "EOF in wrong state");
}
Expand All @@ -92,7 +92,7 @@ public void testBigDecimalOverflow() throws Exception
String INPUT = "q=8E8188888888";
try {
TOML_MAPPER.readTree(INPUT);
Assert.fail("Should not pass");
fail("Should not pass");
} catch (JacksonException e) {
verifyException(e, "Invalid number");
verifyException(e, "8E8188888888");
Expand All @@ -106,7 +106,7 @@ public void testNumberParsingFail50395() throws Exception
String INPUT = "j=427\n-03b-";
try {
TOML_MAPPER.readTree(INPUT);
Assert.fail("Should not pass");
fail("Should not pass");
} catch (StreamReadException e) {
verifyException(e, "Premature end of file");
}
Expand All @@ -121,7 +121,7 @@ public void testStackOverflow50083() throws Exception
}
try {
TOML_MAPPER.readTree(input.toString());
Assert.fail("Should not pass");
fail("Should not pass");
} catch (StreamConstraintsException e) {
String exceptionPrefix = String.format("Document nesting depth (%d) exceeds the maximum allowed",
StreamWriteConstraints.DEFAULT_MAX_DEPTH + 1);
Expand All @@ -139,7 +139,7 @@ protected void verifyException(Throwable e, String... matches)
return;
}
}
Assert.fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
fail("Expected an exception with one of substrings ("+Arrays.asList(matches)+"): got one with message \""+msg+"\"");
}

}
Loading

0 comments on commit f9a5ef3

Please sign in to comment.