Skip to content

Commit 9b0f53f

Browse files
committed
Enable test wrt #337 in master now that snakeyaml-engine supports limits too
1 parent 32254ba commit 9b0f53f

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

yaml/src/test/java/tools/jackson/dataformat/yaml/deser/StreamingParseTest.java

+32-1
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
import java.io.StringWriter;
44
import java.math.BigInteger;
55

6+
import org.snakeyaml.engine.v2.api.LoadSettings;
7+
68
import tools.jackson.core.JsonLocation;
79
import tools.jackson.core.JsonParser;
810
import tools.jackson.core.JsonToken;
9-
11+
import tools.jackson.dataformat.yaml.JacksonYAMLParseException;
1012
import tools.jackson.dataformat.yaml.ModuleTestBase;
13+
import tools.jackson.dataformat.yaml.YAMLFactory;
1114
import tools.jackson.dataformat.yaml.YAMLMapper;
1215
import tools.jackson.dataformat.yaml.YAMLParser;
1316

@@ -602,4 +605,32 @@ public void testTimeLikeValues() throws Exception
602605
assertNull(p.nextToken());
603606
p.close();
604607
}
608+
609+
// [dataformats-text#337]: different setting in 3.0 than 2.x
610+
public void testYamlParseFailsWhenCodePointLimitVerySmall() throws Exception
611+
{
612+
final String YAML = "---\n"
613+
+"content:\n"
614+
+" uri: \"http://javaone.com/keynote.mpg\"\n"
615+
+" title: \"Javaone Keynote\"\n"
616+
+" width: 640\n"
617+
+" height: 480\n"
618+
+" persons:\n"
619+
+" - \"Foo Bar\"\n"
620+
+" - \"Max Power\"\n"
621+
;
622+
LoadSettings loadSettings = LoadSettings.builder()
623+
.setCodePointLimit(5) //5 bytes
624+
.build();
625+
YAMLFactory yamlFactory = YAMLFactory.builder()
626+
.loadSettings(loadSettings)
627+
.build();
628+
YAMLMapper mapper = new YAMLMapper(yamlFactory);
629+
try (JsonParser p = mapper.createParser(YAML)) {
630+
assertToken(JsonToken.START_OBJECT, p.nextToken());
631+
fail("expected to fail by now");
632+
} catch (JacksonYAMLParseException e) {
633+
assertTrue(e.getMessage().startsWith("The incoming YAML document exceeds the limit: 5 code points."));
634+
}
635+
}
605636
}

0 commit comments

Comments
 (0)