Skip to content

Commit 10a9026

Browse files
committed
Unify handling of leading (non-compliant) plus sign: dropped for all values
(ideally would include for all but difficult currently)
1 parent 2999710 commit 10a9026

File tree

4 files changed

+12
-16
lines changed

4 files changed

+12
-16
lines changed

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -1331,7 +1331,7 @@ protected final JsonToken _parseFloatThatStartsWithPeriod() throws IOException {
13311331
}
13321332

13331333
protected final JsonToken _parseFloatThatStartsWithPeriod(final boolean neg,
1334-
final boolean prependSign)
1334+
final boolean hasSign)
13351335
throws IOException
13361336
{
13371337
// [core#611]: allow optionally leading decimal point
@@ -1343,8 +1343,9 @@ protected final JsonToken _parseFloatThatStartsWithPeriod(final boolean neg,
13431343
// (leading sign, period) within same buffer. Caller must ensure this is
13441344
// the case.
13451345
// Little bit suspicious of code paths that would go to "_parseNumber2(...)"
1346+
// 27-Jun-2022, tatu: [core#784] would add plus here too but not yet
13461347
int startPtr = _inputPtr - 1;
1347-
if (prependSign) {
1348+
if (neg) {
13481349
--startPtr;
13491350
}
13501351
return _parseFloat(INT_PERIOD, startPtr, _inputPtr, neg, 0);

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -1006,7 +1006,7 @@ protected final JsonToken _parseFloatThatStartsWithPeriod() throws IOException {
10061006
}
10071007

10081008
protected final JsonToken _parseFloatThatStartsWithPeriod(final boolean neg,
1009-
final boolean prependSign)
1009+
final boolean hasSign)
10101010
throws IOException
10111011
{
10121012
// [core#611]: allow optionally leading decimal point
@@ -1015,8 +1015,9 @@ protected final JsonToken _parseFloatThatStartsWithPeriod(final boolean neg,
10151015
}
10161016
final char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
10171017
int outPtr = 0;
1018-
if (prependSign) {
1019-
outBuf[outPtr++] = neg ? '-' : '+';
1018+
// 27-Jun-2022, tatu: [core#784] would add plus here too but not yet
1019+
if (neg) {
1020+
outBuf[outPtr++] = '-';
10201021
}
10211022
return _parseFloat(outBuf, outPtr, INT_PERIOD, neg, 0);
10221023
}

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

+4-3
Original file line numberDiff line numberDiff line change
@@ -1435,7 +1435,7 @@ protected final JsonToken _parseFloatThatStartsWithPeriod() throws IOException {
14351435
}
14361436

14371437
protected final JsonToken _parseFloatThatStartsWithPeriod(final boolean neg,
1438-
final boolean prependSign)
1438+
final boolean hasSign)
14391439
throws IOException
14401440
{
14411441
// [core#611]: allow optionally leading decimal point
@@ -1444,8 +1444,9 @@ protected final JsonToken _parseFloatThatStartsWithPeriod(final boolean neg,
14441444
}
14451445
final char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
14461446
int outPtr = 0;
1447-
if (prependSign) {
1448-
outBuf[outPtr++] = neg ? '-' : '+';
1447+
// 27-Jun-2022, tatu: [core#784] would add plus here too but not yet
1448+
if (neg) {
1449+
outBuf[outPtr++] = '-';
14491450
}
14501451
return _parseFloat(outBuf, outPtr, INT_PERIOD, neg, 0);
14511452
}

src/test/java/com/fasterxml/jackson/core/read/NonStandardNumberParsingTest.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,6 @@ private void _testLeadingPlusSignInDecimalAllowed(JsonFactory f, int mode) throw
144144
assertEquals(JsonToken.VALUE_NUMBER_INT, p.nextToken());
145145
assertEquals(125.0, p.getValueAsDouble());
146146
assertEquals("125", p.getDecimalValue().toString());
147-
// 27-Jun-2022, tatu: As per [core#784] this SHOULD include leading
148-
// plug sign
149147
assertEquals("125", p.getText());
150148
}
151149
try (JsonParser p = createParser(f, mode, " +0.125 ")) {
@@ -158,12 +156,7 @@ private void _testLeadingPlusSignInDecimalAllowed(JsonFactory f, int mode) throw
158156
assertEquals(JsonToken.VALUE_NUMBER_FLOAT, p.nextToken());
159157
assertEquals(0.125, p.getValueAsDouble());
160158
assertEquals("0.125", p.getDecimalValue().toString());
161-
// 27-Jun-2022, tatu: As per [core#784] this SHOULD include leading
162-
// plug sign. But worse, looks like sometimes it does sometimes not
163-
final String text = p.getText();
164-
if (!"+.125".equals(text) && !".125".equals(text)) {
165-
fail("Bad textual representation: ["+text+"]");
166-
}
159+
assertEquals(".125", p.getText());
167160
}
168161
}
169162

0 commit comments

Comments
 (0)