Skip to content

Commit

Permalink
Merge branch '2.10' into 2.11
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Jun 25, 2020
2 parents 10e45c6 + e3c6b4b commit e0488c5
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 26 deletions.
9 changes: 8 additions & 1 deletion release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ Jochen Schalanda (joschi@github)
* Reported #187: Update to SnakeYAML to 1.26 (from 1.24) to address CVE-2017-18640
(2.10.4)

Sergey Medelyan (smedelyan@github)
* Reported #146: Jackson can't handle underscores in numbers
(2.10.5)

Conor Ward (conor-ward@github)
* Contributed fix for #146: Jackson can't handle underscores in numbers
(2.10.5)

Tyler Carpenter-Rivers (tyler2cr@github)
#7: Add `CsvParser.Feature.EMPTY_STRING_AS_NULL` to allow coercing empty Strings
into `null` values
Expand All @@ -129,4 +137,3 @@ Francesco Tumanischvili (frantuma@github)
* Contibuted fix for #201: (yaml) Improve `MINIMIZE_QUOTES` handling to avoid quoting
for some uses of `#` and `:`
(2.11.1)

5 changes: 5 additions & 0 deletions release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ Project: jackson-datatypes-text
#195 (csv) Adds schema creating csv schema with View
(contributed by Damian S)

2.10.5 (not yet released)

#146: Jackson can't handle underscores in numbers
(reported by Sergey M; fix contributed by Conor W)
2.10.4 (03-May-2020)
#178: Upgrade SnakeYAML to 1.26 (from 1.24)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -743,12 +743,12 @@ protected void _parseNumericValue(int expType) throws IOException
{
// Int or float?
if (_currToken == JsonToken.VALUE_NUMBER_INT) {
int len = _textValue.length();
int len = _cleanedTextValue.length();
if (_numberNegative) {
len--;
}
if (len <= 9) { // definitely fits in int
_numberInt = Integer.parseInt(_textValue);
_numberInt = Integer.parseInt(_cleanedTextValue);
_numTypesValid = NR_INT;
return;
}
Expand Down Expand Up @@ -885,7 +885,7 @@ public String getTypeId() throws IOException
*/

/**
* Helper method used to clean up YAML floating-point value so it can be parsed
* Helper method used to clean up YAML integer value so it can be parsed
* using standard JDK classes.
* Currently this just means stripping out optional underscores.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,43 +13,37 @@
@SuppressWarnings("resource")
public class ParserAutoCloseTest extends ModuleTestBase
{
private final ObjectMapper YAML_MAPPER = newObjectMapper();

public void testParseReaderWithAutoClose() throws IOException {
ObjectMapper yamlMapper = newObjectMapper();

CloseTrackerReader reader = new CloseTrackerReader("foo:bar");
yamlMapper.readTree(reader);
YAML_MAPPER.readTree(reader);

Assert.assertEquals(true, reader.isClosed());
}

public void testParseStreamWithAutoClose() throws IOException {
ObjectMapper yamlMapper = newObjectMapper();

CloseTrackerOutputStream stream = new CloseTrackerOutputStream("foo:bar");
yamlMapper.readTree(stream);
YAML_MAPPER.readTree(stream);

Assert.assertEquals(true, stream.isClosed());
}

@SuppressWarnings("deprecation")
public void testParseReaderWithoutAutoClose() throws IOException {
ObjectMapper yamlMapper = newObjectMapper()
.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE);

CloseTrackerReader reader = new CloseTrackerReader("foo:bar");
yamlMapper.readTree(reader);
YAML_MAPPER.reader()
.without(JsonParser.Feature.AUTO_CLOSE_SOURCE)
.readTree(reader);

Assert.assertEquals(false, reader.isClosed());
}


@SuppressWarnings("deprecation")
public void testParseStreamWithoutAutoClose() throws IOException {
ObjectMapper yamlMapper = newObjectMapper()
.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE);

CloseTrackerOutputStream stream = new CloseTrackerOutputStream("foo:bar");
yamlMapper.readTree(stream);
YAML_MAPPER.reader()
.without(JsonParser.Feature.AUTO_CLOSE_SOURCE)
.readTree(stream);

Assert.assertEquals(false, stream.isClosed());
}
Expand All @@ -72,7 +66,6 @@ public boolean isClosed() {
}
}


public static class CloseTrackerOutputStream extends ByteArrayInputStream {
private boolean closed;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package com.fasterxml.jackson.dataformat.yaml.deser;

import java.io.StringWriter;
import java.math.BigInteger;

import com.fasterxml.jackson.core.JsonLocation;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;

import com.fasterxml.jackson.dataformat.yaml.ModuleTestBase;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLParser;

import java.io.StringWriter;
import java.math.BigInteger;

/**
* Unit tests for checking functioning of the underlying
* parser implementation.
*/
public class StreamingParseTest extends ModuleTestBase
{
final YAMLFactory YAML_F = new YAMLFactory();
private final YAMLFactory YAML_F = new YAMLFactory();

public void testBasic() throws Exception
{
Expand Down Expand Up @@ -312,7 +313,19 @@ public void testIntParsingUnderscoresSm() throws Exception
p.close();
}

// [cbor#4]: accidental recognition as double, with multiple dots
// for [dataformats-text#146]
public void testYamlLongWithUnderscores() throws Exception
{
try (JsonParser p = YAML_F.createParser("v: 1_000_000")) {
assertToken(JsonToken.START_OBJECT, p.nextToken());
assertToken(JsonToken.FIELD_NAME, p.nextToken());
assertEquals("v", p.currentName());
assertToken(JsonToken.VALUE_NUMBER_INT, p.nextToken());
assertEquals(1000000, p.getIntValue());
}
}

// accidental recognition as double, with multiple dots
public void testDoubleParsing() throws Exception
{
// First, test out valid use case.
Expand Down

0 comments on commit e0488c5

Please sign in to comment.