diff --git a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/YAML.java b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/YAML.java index 780eaff1ed..92e12e561f 100644 --- a/planetiler-core/src/main/java/com/onthegomap/planetiler/util/YAML.java +++ b/planetiler-core/src/main/java/com/onthegomap/planetiler/util/YAML.java @@ -19,7 +19,7 @@ public class YAML { private YAML() {} - private static final Load snakeYaml = new Load(LoadSettings.builder().build()); + private static final Load snakeYaml = new Load(LoadSettings.builder().setCodePointLimit(Integer.MAX_VALUE).build()); public static final ObjectMapper jackson = new ObjectMapper(); public static T load(Path file, Class clazz) { diff --git a/planetiler-core/src/test/java/com/onthegomap/planetiler/util/YamlTest.java b/planetiler-core/src/test/java/com/onthegomap/planetiler/util/YamlTest.java new file mode 100644 index 0000000000..59c5201bfb --- /dev/null +++ b/planetiler-core/src/test/java/com/onthegomap/planetiler/util/YamlTest.java @@ -0,0 +1,48 @@ +package com.onthegomap.planetiler.util; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.junit.jupiter.api.Test; + +class YamlTest { + @Test + void testLoadYamlRaw() { + assertEquals(Map.of("a", 1), YAML.load(""" + a: 1 + """, Object.class)); + } + + @Test + void testLoadYamlToClass() { + record Result(int a) {} + assertEquals(new Result(1), YAML.load(""" + a: 1 + """, Result.class)); + } + + @Test + void testLoadLargeYamlList() { + StringBuilder builder = new StringBuilder(); + List expected = new ArrayList<>(); + for (int i = 0; i < 500_000; i++) { + builder.append("\n- ").append(i); + expected.add(i); + } + assertEquals(expected, YAML.load(builder.toString(), List.class)); + } + + @Test + void testLoadLargeYamlMap() { + StringBuilder builder = new StringBuilder(); + Map expected = new HashMap<>(); + for (int i = 0; i < 500_000; i++) { + builder.append('\n').append(i).append(": ").append(i); + expected.put(Integer.toString(i), i); + } + assertEquals(expected, YAML.load(builder.toString(), Map.class)); + } +}