Skip to content

Commit ab89bf2

Browse files
committed
Update release notes wrt #774, minor clean up
1 parent c2ca290 commit ab89bf2

File tree

6 files changed

+97
-62
lines changed

6 files changed

+97
-62
lines changed

release-notes/CREDITS-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ PJ Fanning (pjfanning@github)
296296
(2.14.0)
297297
* Contributed #773: Add option to accept non-standard trailing decimal point
298298
(2.14.0)
299+
* Contributed #774: Add a feature to allow leading plus sign
300+
(`JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS`)
301+
(2.14.0)
299302

300303
Ilya Golovin (ilgo0413@github)
301304
* Contributed #684: Add "JsonPointer#appendProperty" and "JsonPointer#appendIndex"

release-notes/VERSION-2.x

+3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ JSON library.
4242
#764: `JsonFactory.createGenerator()` with `File` may leak `OutputStream`s
4343
#773: Add option to accept non-standard trailing decimal point
4444
(contributed by @pjfanning)
45+
#774: Add a feature to allow leading plus sign
46+
(`JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS`)
47+
(contributed by @pjfanning)
4548

4649
2.13.3 (14-May-2022)
4750

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

+35-24
Original file line numberDiff line numberDiff line change
@@ -777,13 +777,13 @@ public final JsonToken nextToken() throws IOException
777777
break;
778778

779779
case '-':
780-
t = _parseNegNumber();
780+
t = _parsePossibleNumber(true);
781781
break;
782782
case '+':
783-
if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
784-
t = _handleOddValue(i);
783+
if (isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
784+
t = _parsePossibleNumber(false);
785785
} else {
786-
t = _parsePosNumber();
786+
t = _handleOddValue(i);
787787
}
788788
break;
789789
case '.': // [core#61]]
@@ -980,7 +980,14 @@ public String nextFieldName() throws IOException
980980

981981
switch (i) {
982982
case '-':
983-
t = _parseNegNumber();
983+
t = _parsePossibleNumber(true);
984+
break;
985+
case '+':
986+
if (isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
987+
t = _parsePossibleNumber(false);
988+
} else {
989+
t = _handleOddValue(i);
990+
}
984991
break;
985992
case '.': // [core#61]]
986993
t = _parseFloatThatStartsWithPeriod();
@@ -1052,7 +1059,14 @@ private final void _isNextTokenNameYes(int i) throws IOException
10521059
_nextToken = JsonToken.VALUE_NULL;
10531060
return;
10541061
case '-':
1055-
_nextToken = _parseNegNumber();
1062+
_nextToken = _parsePossibleNumber(true);
1063+
return;
1064+
case '+':
1065+
if (isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
1066+
_nextToken = _parsePossibleNumber(false);
1067+
} else {
1068+
_nextToken = _handleOddValue(i);
1069+
}
10561070
return;
10571071
case '.': // [core#61]]
10581072
_nextToken = _parseFloatThatStartsWithPeriod();
@@ -1090,9 +1104,16 @@ protected boolean _isNextTokenNameMaybe(int i, String nameToMatch) throws IOExce
10901104
JsonToken t;
10911105
switch (i) {
10921106
case '-':
1093-
t = _parseNegNumber();
1107+
t = _parsePossibleNumber(true);
10941108
break;
1095-
case '.': // [core#61]]
1109+
case '+':
1110+
if (isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
1111+
t = _parsePossibleNumber(false);
1112+
} else {
1113+
t = _handleOddValue(i);
1114+
}
1115+
break;
1116+
case '.': // [core#61]
10961117
t = _parseFloatThatStartsWithPeriod();
10971118
break;
10981119
case '0':
@@ -1156,7 +1177,7 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
11561177
_matchToken("null", 1);
11571178
return (_currToken = JsonToken.VALUE_NULL);
11581179
case '-':
1159-
return (_currToken = _parseNegNumber());
1180+
return (_currToken = _parsePossibleNumber(true));
11601181
/* Should we have separate handling for plus? Although
11611182
* it is not allowed per se, it may be erroneously used,
11621183
* and could be indicated by a more specific error message.
@@ -1456,17 +1477,7 @@ private final JsonToken _parseFloat(int ch, int startPtr, int ptr, boolean neg,
14561477
return resetFloat(neg, intLen, fractLen, expLen);
14571478
}
14581479

1459-
protected final JsonToken _parsePosNumber() throws IOException
1460-
{
1461-
return _parsePossibleNumber(false);
1462-
}
1463-
1464-
protected final JsonToken _parseNegNumber() throws IOException
1465-
{
1466-
return _parsePossibleNumber(true);
1467-
}
1468-
1469-
private JsonToken _parsePossibleNumber(final boolean negative) throws IOException
1480+
private final JsonToken _parsePossibleNumber(final boolean negative) throws IOException
14701481
{
14711482
int ptr = _inputPtr;
14721483
int startPtr = negative ? ptr-1 : ptr; // to include sign/digit already read
@@ -1725,14 +1736,14 @@ protected JsonToken _handleInvalidNumberStart(int ch, boolean negative) throws I
17251736
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
17261737
return resetAsNaN(match, negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY);
17271738
}
1728-
_reportError("Non-standard token '"+match+"': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
1739+
_reportError("Non-standard token '"+match+"': enable `JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS` to allow");
17291740
} else if (ch == 'n') {
17301741
String match = negative ? "-Infinity" :"+Infinity";
17311742
_matchToken(match, 3);
17321743
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
17331744
return resetAsNaN(match, negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY);
17341745
}
1735-
_reportError("Non-standard token '"+match+"': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
1746+
_reportError("Non-standard token '"+match+"': enable `JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS` to allow");
17361747
}
17371748
}
17381749
reportUnexpectedNumberChar(ch, "expected digit (0-9) to follow minus sign, for valid numeric value");
@@ -2000,14 +2011,14 @@ protected JsonToken _handleOddValue(int i) throws IOException
20002011
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
20012012
return resetAsNaN("NaN", Double.NaN);
20022013
}
2003-
_reportError("Non-standard token 'NaN': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
2014+
_reportError("Non-standard token 'NaN': enable `JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS` to allow");
20042015
break;
20052016
case 'I':
20062017
_matchToken("Infinity", 1);
20072018
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
20082019
return resetAsNaN("Infinity", Double.POSITIVE_INFINITY);
20092020
}
2010-
_reportError("Non-standard token 'Infinity': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
2021+
_reportError("Non-standard token 'Infinity': enable `JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS` to allow");
20112022
break;
20122023
case '+': // note: '-' is taken as number
20132024
if (_inputPtr >= _inputEnd) {

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

+19-12
Original file line numberDiff line numberDiff line change
@@ -661,10 +661,10 @@ public JsonToken nextToken() throws IOException
661661
t = _parseNegNumber();
662662
break;
663663
case '+':
664-
if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
665-
t = _handleUnexpectedValue(i);
666-
} else {
664+
if (isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
667665
t = _parsePosNumber();
666+
} else {
667+
t = _handleUnexpectedValue(i);
668668
}
669669
break;
670670
case '.': // as per [core#611]
@@ -733,10 +733,10 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
733733
case '-':
734734
return (_currToken = _parseNegNumber());
735735
case '+':
736-
if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
737-
return (_currToken = _handleUnexpectedValue(i));
736+
if (isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
737+
return (_currToken = _parsePosNumber());
738738
}
739-
return (_currToken = _parsePosNumber());
739+
return (_currToken = _handleUnexpectedValue(i));
740740
case '.': // as per [core#611]
741741
return (_currToken = _parseFloatThatStartsWithPeriod());
742742
case '0':
@@ -844,6 +844,13 @@ public String nextFieldName() throws IOException
844844
case '-':
845845
t = _parseNegNumber();
846846
break;
847+
case '+':
848+
if (isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
849+
t = _parsePosNumber();
850+
} else {
851+
t = _handleUnexpectedValue(i);
852+
}
853+
break;
847854
case '.': // as per [core#611]
848855
t = _parseFloatThatStartsWithPeriod();
849856
case '0':
@@ -1073,17 +1080,17 @@ protected JsonToken _parsePosNumber(int c) throws IOException
10731080
return resetInt(false, intLen);
10741081
}
10751082

1076-
protected JsonToken _parsePosNumber() throws IOException
1083+
protected final JsonToken _parsePosNumber() throws IOException
10771084
{
10781085
return _parsePossibleNumber(false);
10791086
}
10801087

1081-
protected JsonToken _parseNegNumber() throws IOException
1088+
protected final JsonToken _parseNegNumber() throws IOException
10821089
{
10831090
return _parsePossibleNumber(true);
10841091
}
10851092

1086-
private JsonToken _parsePossibleNumber(boolean negative) throws IOException
1093+
private final JsonToken _parsePossibleNumber(boolean negative) throws IOException
10871094
{
10881095
char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
10891096
int outPtr = 0;
@@ -2126,14 +2133,14 @@ protected JsonToken _handleUnexpectedValue(int c)
21262133
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
21272134
return resetAsNaN("NaN", Double.NaN);
21282135
}
2129-
_reportError("Non-standard token 'NaN': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
2136+
_reportError("Non-standard token 'NaN': enable `JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS` to allow");
21302137
break;
21312138
case 'I':
21322139
_matchToken("Infinity", 1);
21332140
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
21342141
return resetAsNaN("Infinity", Double.POSITIVE_INFINITY);
21352142
}
2136-
_reportError("Non-standard token 'Infinity': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
2143+
_reportError("Non-standard token 'Infinity': enable `JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS` to allow");
21372144
break;
21382145
case '+': // note: '-' is taken as number
21392146
return _handleInvalidNumberStart(_inputData.readUnsignedByte(), false);
@@ -2244,7 +2251,7 @@ protected JsonToken _handleInvalidNumberStart(int ch, boolean neg)
22442251
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
22452252
return resetAsNaN(match, neg ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY);
22462253
}
2247-
_reportError("Non-standard token '"+match+"': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
2254+
_reportError("Non-standard token '"+match+"': enable `JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS` to allow");
22482255
}
22492256
reportUnexpectedNumberChar(ch, "expected digit (0-9) to follow minus sign, for valid numeric value");
22502257
return null;

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

+36-25
Original file line numberDiff line numberDiff line change
@@ -812,13 +812,13 @@ public JsonToken nextToken() throws IOException
812812

813813
switch (i) {
814814
case '-':
815-
t = _parseNegNumber();
815+
t = _parsePossibleNumber(true);
816816
break;
817817
case '+':
818-
if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
819-
t = _handleUnexpectedValue(i);
818+
if (isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
819+
t = _parsePossibleNumber(false);
820820
} else {
821-
t = _parsePosNumber();
821+
t = _handleUnexpectedValue(i);
822822
}
823823
break;
824824
case '.': // [core#611]:
@@ -885,12 +885,12 @@ private final JsonToken _nextTokenNotInObject(int i) throws IOException
885885
_matchNull();
886886
return (_currToken = JsonToken.VALUE_NULL);
887887
case '-':
888-
return (_currToken = _parseNegNumber());
888+
return (_currToken = _parsePossibleNumber(true));
889889
case '+':
890890
if (!isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
891891
return (_currToken = _handleUnexpectedValue(i));
892892
}
893-
return (_currToken = _parsePosNumber());
893+
return (_currToken = _parsePossibleNumber(false));
894894
case '.': // [core#611]:
895895
return (_currToken = _parseFloatThatStartsWithPeriod());
896896
case '0':
@@ -1092,7 +1092,14 @@ public String nextFieldName() throws IOException
10921092
JsonToken t;
10931093
switch (i) {
10941094
case '-':
1095-
t = _parseNegNumber();
1095+
t = _parsePossibleNumber(true);
1096+
break;
1097+
case '+':
1098+
if (isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
1099+
t = _parsePossibleNumber(false);
1100+
} else {
1101+
t = _handleUnexpectedValue(i);
1102+
}
10961103
break;
10971104
case '.': // [core#611]:
10981105
t = _parseFloatThatStartsWithPeriod();
@@ -1213,9 +1220,16 @@ private final void _isNextTokenNameYes(int i) throws IOException
12131220
_nextToken = JsonToken.VALUE_NULL;
12141221
return;
12151222
case '-':
1216-
_nextToken = _parseNegNumber();
1223+
_nextToken = _parsePossibleNumber(true);
12171224
return;
1218-
case '.': // [core#611]:
1225+
case '+':
1226+
if (isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
1227+
_nextToken = _parsePossibleNumber(false);
1228+
} else {
1229+
_nextToken = _handleUnexpectedValue(i);
1230+
}
1231+
return;
1232+
case '.': // [core#611]
12191233
_nextToken = _parseFloatThatStartsWithPeriod();
12201234
return;
12211235
case '0':
@@ -1273,9 +1287,16 @@ private final boolean _isNextTokenNameMaybe(int i, SerializableString str) throw
12731287
t = JsonToken.VALUE_NULL;
12741288
break;
12751289
case '-':
1276-
t = _parseNegNumber();
1290+
t = _parsePossibleNumber(true);
12771291
break;
1278-
case '.': // [core#611]:
1292+
case '+':
1293+
if (isEnabled(JsonReadFeature.ALLOW_LEADING_PLUS_SIGN_FOR_NUMBERS.mappedFeature())) {
1294+
t = _parsePossibleNumber(false);
1295+
} else {
1296+
t = _handleUnexpectedValue(i);
1297+
}
1298+
break;
1299+
case '.': // [core#611]
12791300
t = _parseFloatThatStartsWithPeriod();
12801301
break;
12811302
case '0':
@@ -1482,17 +1503,7 @@ protected JsonToken _parsePosNumber(int c) throws IOException
14821503
return resetInt(false, intLen);
14831504
}
14841505

1485-
protected JsonToken _parsePosNumber() throws IOException
1486-
{
1487-
return _parsePossibleNumber(false);
1488-
}
1489-
1490-
protected JsonToken _parseNegNumber() throws IOException
1491-
{
1492-
return _parsePossibleNumber(true);
1493-
}
1494-
1495-
private JsonToken _parsePossibleNumber(boolean negative) throws IOException
1506+
private final JsonToken _parsePossibleNumber(boolean negative) throws IOException
14961507
{
14971508
char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
14981509
int outPtr = 0;
@@ -2735,14 +2746,14 @@ protected JsonToken _handleUnexpectedValue(int c) throws IOException
27352746
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
27362747
return resetAsNaN("NaN", Double.NaN);
27372748
}
2738-
_reportError("Non-standard token 'NaN': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
2749+
_reportError("Non-standard token 'NaN': enable `JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS` to allow");
27392750
break;
27402751
case 'I':
27412752
_matchToken("Infinity", 1);
27422753
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
27432754
return resetAsNaN("Infinity", Double.POSITIVE_INFINITY);
27442755
}
2745-
_reportError("Non-standard token 'Infinity': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
2756+
_reportError("Non-standard token 'Infinity': enable `JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS` to allow");
27462757
break;
27472758
case '+': // note: '-' is taken as number
27482759
if (_inputPtr >= _inputEnd) {
@@ -2880,7 +2891,7 @@ protected JsonToken _handleInvalidNumberStart(int ch, boolean neg) throws IOExce
28802891
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
28812892
return resetAsNaN(match, neg ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY);
28822893
}
2883-
_reportError("Non-standard token '%s': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow",
2894+
_reportError("Non-standard token '%s': enable `JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS` to allow",
28842895
match);
28852896
}
28862897
reportUnexpectedNumberChar(ch, "expected digit (0-9) to follow minus sign, for valid numeric value");

src/main/java/com/fasterxml/jackson/core/json/async/NonBlockingJsonParserBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -839,7 +839,7 @@ protected final JsonToken _valueNonStdNumberComplete(int type) throws IOExceptio
839839
String tokenStr = NON_STD_TOKENS[type];
840840
_textBuffer.resetWithString(tokenStr);
841841
if (!isEnabled(Feature.ALLOW_NON_NUMERIC_NUMBERS)) {
842-
_reportError("Non-standard token '%s': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow",
842+
_reportError("Non-standard token '%s': enable `JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS` to allow",
843843
tokenStr);
844844
}
845845
_intLength = 0;

0 commit comments

Comments
 (0)