Skip to content

Commit e3c6b4b

Browse files
committed
Update release notes wrt #146; minor clean up
1 parent 2cf9d0a commit e3c6b4b

File tree

5 files changed

+38
-44
lines changed

5 files changed

+38
-44
lines changed

release-notes/CREDITS-2.x

+8
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,11 @@ Jason van Zyl (jvanzyl@github)
102102
Jochen Schalanda (joschi@github)
103103
* Reported #187: Update to SnakeYAML to 1.26 (from 1.24) to address CVE-2017-18640
104104
(2.10.4)
105+
106+
Sergey Medelyan (smedelyan@github)
107+
* Reported #146: Jackson can't handle underscores in numbers
108+
(2.10.5)
109+
110+
Conor Ward (conor-ward@github)
111+
* Contributed fix for #146: Jackson can't handle underscores in numbers
112+
(2.10.5)

release-notes/VERSION-2.x

+5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ Modules:
88
=== Releases ===
99
------------------------------------------------------------------------
1010

11+
2.10.5 (not yet released)
12+
13+
#146: Jackson can't handle underscores in numbers
14+
(reported by Sergey M; fix contributed by Conor W)
15+
1116
2.10.4 (03-May-2020)
1217
1318
#179 (properties): `JavaPropsMapper` doesn't close the .properties file

yaml/src/main/java/com/fasterxml/jackson/dataformat/yaml/YAMLParser.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,7 @@ public String getTypeId() throws IOException
885885
*/
886886

887887
/**
888-
* Helper method used to clean up YAML floating-point value so it can be parsed
888+
* Helper method used to clean up YAML integer value so it can be parsed
889889
* using standard JDK classes.
890890
* Currently this just means stripping out optional underscores.
891891
*/

yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/ParserAutoCloseTest.java

+10-17
Original file line numberDiff line numberDiff line change
@@ -13,43 +13,37 @@
1313
@SuppressWarnings("resource")
1414
public class ParserAutoCloseTest extends ModuleTestBase
1515
{
16+
private final ObjectMapper YAML_MAPPER = newObjectMapper();
17+
1618
public void testParseReaderWithAutoClose() throws IOException {
17-
ObjectMapper yamlMapper = newObjectMapper();
1819

1920
CloseTrackerReader reader = new CloseTrackerReader("foo:bar");
20-
yamlMapper.readTree(reader);
21+
YAML_MAPPER.readTree(reader);
2122

2223
Assert.assertEquals(true, reader.isClosed());
2324
}
2425

2526
public void testParseStreamWithAutoClose() throws IOException {
26-
ObjectMapper yamlMapper = newObjectMapper();
27-
2827
CloseTrackerOutputStream stream = new CloseTrackerOutputStream("foo:bar");
29-
yamlMapper.readTree(stream);
28+
YAML_MAPPER.readTree(stream);
3029

3130
Assert.assertEquals(true, stream.isClosed());
3231
}
3332

34-
@SuppressWarnings("deprecation")
3533
public void testParseReaderWithoutAutoClose() throws IOException {
36-
ObjectMapper yamlMapper = newObjectMapper()
37-
.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
38-
3934
CloseTrackerReader reader = new CloseTrackerReader("foo:bar");
40-
yamlMapper.readTree(reader);
35+
YAML_MAPPER.reader()
36+
.without(JsonParser.Feature.AUTO_CLOSE_SOURCE)
37+
.readTree(reader);
4138

4239
Assert.assertEquals(false, reader.isClosed());
4340
}
4441

45-
46-
@SuppressWarnings("deprecation")
4742
public void testParseStreamWithoutAutoClose() throws IOException {
48-
ObjectMapper yamlMapper = newObjectMapper()
49-
.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
50-
5143
CloseTrackerOutputStream stream = new CloseTrackerOutputStream("foo:bar");
52-
yamlMapper.readTree(stream);
44+
YAML_MAPPER.reader()
45+
.without(JsonParser.Feature.AUTO_CLOSE_SOURCE)
46+
.readTree(stream);
5347

5448
Assert.assertEquals(false, stream.isClosed());
5549
}
@@ -72,7 +66,6 @@ public boolean isClosed() {
7266
}
7367
}
7468

75-
7669
public static class CloseTrackerOutputStream extends ByteArrayInputStream {
7770
private boolean closed;
7871

yaml/src/test/java/com/fasterxml/jackson/dataformat/yaml/deser/StreamingParseTest.java

+14-26
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
package com.fasterxml.jackson.dataformat.yaml.deser;
22

3+
import java.io.StringWriter;
4+
import java.math.BigInteger;
5+
36
import com.fasterxml.jackson.core.JsonParser;
47
import com.fasterxml.jackson.core.JsonToken;
5-
import com.fasterxml.jackson.databind.ObjectMapper;
8+
69
import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
710
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
811
import com.fasterxml.jackson.dataformat.yaml.YAMLParser;
912

10-
import java.io.StringWriter;
11-
import java.math.BigInteger;
12-
1313
/**
1414
* Unit tests for checking functioning of the underlying
1515
* parser implementation.
1616
*/
1717
public class StreamingParseTest extends ModuleTestBase
1818
{
19-
final YAMLFactory YAML_F = new YAMLFactory();
19+
private final YAMLFactory YAML_F = new YAMLFactory();
2020

2121
public void testBasic() throws Exception
2222
{
@@ -300,16 +300,19 @@ public void testIntParsingUnderscoresSm() throws Exception
300300
p.close();
301301
}
302302

303+
// for [dataformats-text#146]
303304
public void testYamlLongWithUnderscores() throws Exception
304305
{
305-
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
306-
LongHolder longHolder = mapper.readValue("v: 1_000_000", LongHolder.class);
307-
assertNotNull(longHolder);
308-
assertEquals(LongHolder.class, longHolder.getClass());
309-
assertEquals(Long.valueOf(1000000), longHolder.getV());
306+
try (JsonParser p = YAML_F.createParser("v: 1_000_000")) {
307+
assertToken(JsonToken.START_OBJECT, p.nextToken());
308+
assertToken(JsonToken.FIELD_NAME, p.nextToken());
309+
assertEquals("v", p.currentName());
310+
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
311+
assertEquals(1000000, p.getIntValue());
312+
}
310313
}
311314

312-
// [cbor#4]: accidental recognition as double, with multiple dots
315+
// accidental recognition as double, with multiple dots
313316
public void testDoubleParsing() throws Exception
314317
{
315318
// First, test out valid use case.
@@ -581,19 +584,4 @@ public void testTimeLikeValues() throws Exception
581584
assertNull(p.nextToken());
582585
p.close();
583586
}
584-
585-
static class LongHolder
586-
{
587-
private Long v;
588-
589-
public Long getV()
590-
{
591-
return v;
592-
}
593-
594-
public void setV(Long v)
595-
{
596-
this.v = v;
597-
}
598-
}
599587
}

0 commit comments

Comments
 (0)