Skip to content

Commit

Permalink
Start merging #611 piece by piece
Browse files Browse the repository at this point in the history
  • Loading branch information
cowtowncoder committed Apr 21, 2020
1 parent 517b1bf commit ebdc0b5
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 5 deletions.
17 changes: 13 additions & 4 deletions src/main/java/com/fasterxml/jackson/core/TSFBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,25 @@ public B outputDecorator(OutputDecorator dec) {
// // // Support for subtypes

protected void _legacyEnable(JsonParser.Feature f) {
_streamReadFeatures |= f.getMask();
if (f != null) {
_streamReadFeatures |= f.getMask();
}
}

protected void _legacyDisable(JsonParser.Feature f) {
_streamReadFeatures &= ~f.getMask();
if (f != null) {
_streamReadFeatures &= ~f.getMask();
}
}

protected void _legacyEnable(JsonGenerator.Feature f) {
_streamWriteFeatures |= f.getMask();
if (f != null) {
_streamWriteFeatures |= f.getMask();
}
}
protected void _legacyDisable(JsonGenerator.Feature f) {
_streamWriteFeatures &= ~f.getMask();
if (f != null) {
_streamWriteFeatures &= ~f.getMask();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,20 @@ public enum JsonReadFeature
*/
@SuppressWarnings("deprecation")
ALLOW_LEADING_ZEROS_FOR_NUMBERS(false, JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS),


/**
* Feature that determines whether parser will allow
* JSON decimal numbers to start with a decimal point
* (like: .123). If enabled, no exception is thrown, and the number
* is parsed as though a leading 0 had been present.
*<p>
* Since JSON specification does not allow leading decimal,
* this is a non-standard feature, and as such disabled by default.
*
* @since 2.11
*/
ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS(false, null),

/**
* Feature that allows parser to recognize set of
* "Not-a-Number" (NaN) tokens as legal floating number
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.fasterxml.jackson.failing;

import com.fasterxml.jackson.core.*;
import com.fasterxml.jackson.core.json.JsonReadFeature;

public class NonStandardNumbers611Test
extends com.fasterxml.jackson.core.BaseTest
{
/**
* The format ".NNN" (as opposed to "0.NNN") is not valid JSON, so this should fail
*/
public void testLeadingDotInDecimal() throws Exception {
for (int mode : ALL_MODES) {
JsonParser p = createParser(mode, " .123 ");
try {
p.nextToken();
fail("Should not pass");
} catch (JsonParseException e) {
verifyException(e, "Unexpected character ('.'");
}
p.close();
}
}

public void testLeadingDotInDecimalAllowed() throws Exception {
final JsonFactory f = JsonFactory.builder()
.enable(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS)
.build();

// TODO:
/*
for (int mode : ALL_MODES) {
_testLeadingDotInDecimalAllowed(f, mode);
}
*/


_testLeadingDotInDecimalAllowed(f, MODE_INPUT_STREAM);
_testLeadingDotInDecimalAllowed(f, MODE_INPUT_STREAM_THROTTLED);
_testLeadingDotInDecimalAllowed(f, MODE_READER);
_testLeadingDotInDecimalAllowed(f, MODE_DATA_INPUT);
}

private void _testLeadingDotInDecimalAllowed(JsonFactory f, int mode) throws Exception
{
JsonParser p = createParser(f, mode, " .123 ");
assertEquals(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
assertEquals(0.123, p.getValueAsDouble());
assertEquals("0.123", p.getDecimalValue().toString());
p.close();
}
}

0 comments on commit ebdc0b5

Please sign in to comment.