Skip to content

Commit ebdc0b5

Browse files
committed
Start merging #611 piece by piece
1 parent 517b1bf commit ebdc0b5

File tree

3 files changed

+79
-5
lines changed

3 files changed

+79
-5
lines changed

src/main/java/com/fasterxml/jackson/core/TSFBuilder.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,25 @@ public B outputDecorator(OutputDecorator dec) {
276276
// // // Support for subtypes
277277

278278
protected void _legacyEnable(JsonParser.Feature f) {
279-
_streamReadFeatures |= f.getMask();
279+
if (f != null) {
280+
_streamReadFeatures |= f.getMask();
281+
}
280282
}
283+
281284
protected void _legacyDisable(JsonParser.Feature f) {
282-
_streamReadFeatures &= ~f.getMask();
285+
if (f != null) {
286+
_streamReadFeatures &= ~f.getMask();
287+
}
283288
}
284289

285290
protected void _legacyEnable(JsonGenerator.Feature f) {
286-
_streamWriteFeatures |= f.getMask();
291+
if (f != null) {
292+
_streamWriteFeatures |= f.getMask();
293+
}
287294
}
288295
protected void _legacyDisable(JsonGenerator.Feature f) {
289-
_streamWriteFeatures &= ~f.getMask();
296+
if (f != null) {
297+
_streamWriteFeatures &= ~f.getMask();
298+
}
290299
}
291300
}

src/main/java/com/fasterxml/jackson/core/json/JsonReadFeature.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,20 @@ public enum JsonReadFeature
106106
*/
107107
@SuppressWarnings("deprecation")
108108
ALLOW_LEADING_ZEROS_FOR_NUMBERS(false, JsonParser.Feature.ALLOW_NUMERIC_LEADING_ZEROS),
109-
109+
110+
/**
111+
* Feature that determines whether parser will allow
112+
* JSON decimal numbers to start with a decimal point
113+
* (like: .123). If enabled, no exception is thrown, and the number
114+
* is parsed as though a leading 0 had been present.
115+
*<p>
116+
* Since JSON specification does not allow leading decimal,
117+
* this is a non-standard feature, and as such disabled by default.
118+
*
119+
* @since 2.11
120+
*/
121+
ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS(false, null),
122+
110123
/**
111124
* Feature that allows parser to recognize set of
112125
* "Not-a-Number" (NaN) tokens as legal floating number
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package com.fasterxml.jackson.failing;
2+
3+
import com.fasterxml.jackson.core.*;
4+
import com.fasterxml.jackson.core.json.JsonReadFeature;
5+
6+
public class NonStandardNumbers611Test
7+
extends com.fasterxml.jackson.core.BaseTest
8+
{
9+
/**
10+
* The format ".NNN" (as opposed to "0.NNN") is not valid JSON, so this should fail
11+
*/
12+
public void testLeadingDotInDecimal() throws Exception {
13+
for (int mode : ALL_MODES) {
14+
JsonParser p = createParser(mode, " .123 ");
15+
try {
16+
p.nextToken();
17+
fail("Should not pass");
18+
} catch (JsonParseException e) {
19+
verifyException(e, "Unexpected character ('.'");
20+
}
21+
p.close();
22+
}
23+
}
24+
25+
public void testLeadingDotInDecimalAllowed() throws Exception {
26+
final JsonFactory f = JsonFactory.builder()
27+
.enable(JsonReadFeature.ALLOW_LEADING_DECIMAL_POINT_FOR_NUMBERS)
28+
.build();
29+
30+
// TODO:
31+
/*
32+
for (int mode : ALL_MODES) {
33+
_testLeadingDotInDecimalAllowed(f, mode);
34+
}
35+
*/
36+
37+
38+
_testLeadingDotInDecimalAllowed(f, MODE_INPUT_STREAM);
39+
_testLeadingDotInDecimalAllowed(f, MODE_INPUT_STREAM_THROTTLED);
40+
_testLeadingDotInDecimalAllowed(f, MODE_READER);
41+
_testLeadingDotInDecimalAllowed(f, MODE_DATA_INPUT);
42+
}
43+
44+
private void _testLeadingDotInDecimalAllowed(JsonFactory f, int mode) throws Exception
45+
{
46+
JsonParser p = createParser(f, mode, " .123 ");
47+
assertEquals(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
48+
assertEquals(0.123, p.getValueAsDouble());
49+
assertEquals("0.123", p.getDecimalValue().toString());
50+
p.close();
51+
}
52+
}

0 commit comments

Comments
 (0)