|
3 | 3 | import java.io.StringWriter;
|
4 | 4 | import java.math.BigInteger;
|
5 | 5 |
|
| 6 | +import org.snakeyaml.engine.v2.api.LoadSettings; |
| 7 | + |
6 | 8 | import tools.jackson.core.JsonLocation;
|
7 | 9 | import tools.jackson.core.JsonParser;
|
8 | 10 | import tools.jackson.core.JsonToken;
|
9 |
| - |
| 11 | +import tools.jackson.dataformat.yaml.JacksonYAMLParseException; |
10 | 12 | import tools.jackson.dataformat.yaml.ModuleTestBase;
|
| 13 | +import tools.jackson.dataformat.yaml.YAMLFactory; |
11 | 14 | import tools.jackson.dataformat.yaml.YAMLMapper;
|
12 | 15 | import tools.jackson.dataformat.yaml.YAMLParser;
|
13 | 16 |
|
@@ -602,4 +605,32 @@ public void testTimeLikeValues() throws Exception
|
602 | 605 | assertNull(p.nextToken());
|
603 | 606 | p.close();
|
604 | 607 | }
|
| 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 | + } |
605 | 636 | }
|
0 commit comments