Skip to content

Commit 1d63a6b

Browse files
committed
more of #467
1 parent d6e77d0 commit 1d63a6b

12 files changed

+82
-54
lines changed

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ public enum Feature {
124124
*<p>
125125
* Since JSON specification requires quoting for all control characters,
126126
* this is a non-standard feature, and as such disabled by default.
127+
*
128+
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER} instead
127129
*/
130+
@Deprecated
128131
ALLOW_UNQUOTED_CONTROL_CHARS(false),
129132

130133
/**
@@ -135,7 +138,10 @@ public enum Feature {
135138
*<p>
136139
* Since JSON specification requires quoting for all control characters,
137140
* this is a non-standard feature, and as such disabled by default.
141+
*
142+
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER} instead
138143
*/
144+
@Deprecated
139145
ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER(false),
140146

141147
/**
@@ -147,9 +153,9 @@ public enum Feature {
147153
*<p>
148154
* Since JSON specification does not allow leading zeroes,
149155
* this is a non-standard feature, and as such disabled by default.
150-
*
151-
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_LEADING_ZEROS_FOR_NUMBERS} instead
152-
*/
156+
*
157+
* @deprecated Since 2.10 use {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_LEADING_ZEROS_FOR_NUMBERS} instead
158+
*/
153159
@Deprecated
154160
ALLOW_NUMERIC_LEADING_ZEROS(false),
155161

src/main/java/com/fasterxml/jackson/core/base/ParserBase.java

+30
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.Arrays;
77

88
import com.fasterxml.jackson.core.*;
9+
import com.fasterxml.jackson.core.JsonParser.Feature;
910
import com.fasterxml.jackson.core.io.IOContext;
1011
import com.fasterxml.jackson.core.io.NumberInput;
1112
import com.fasterxml.jackson.core.json.DupDetector;
@@ -998,6 +999,35 @@ protected void _reportMismatchedEndMarker(int actCh, char expCh) throws JsonPars
998999
(char) actCh, expCh, ctxt.typeDesc(), ctxt.getStartLocation(_getSourceReference())));
9991000
}
10001001

1002+
@SuppressWarnings("deprecation")
1003+
protected char _handleUnrecognizedCharacterEscape(char ch) throws JsonProcessingException {
1004+
// as per [JACKSON-300]
1005+
if (isEnabled(Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER)) {
1006+
return ch;
1007+
}
1008+
// and [JACKSON-548]
1009+
if (ch == '\'' && isEnabled(Feature.ALLOW_SINGLE_QUOTES)) {
1010+
return ch;
1011+
}
1012+
_reportError("Unrecognized character escape "+_getCharDesc(ch));
1013+
return ch;
1014+
}
1015+
1016+
/**
1017+
* Method called to report a problem with unquoted control character.
1018+
* Note: it is possible to suppress some instances of
1019+
* exception by enabling {@link Feature#ALLOW_UNQUOTED_CONTROL_CHARS}.
1020+
*/
1021+
@SuppressWarnings("deprecation")
1022+
protected void _throwUnquotedSpace(int i, String ctxtDesc) throws JsonParseException {
1023+
// JACKSON-208; possible to allow unquoted control chars:
1024+
if (!isEnabled(Feature.ALLOW_UNQUOTED_CONTROL_CHARS) || i > INT_SPACE) {
1025+
char c = (char) i;
1026+
String msg = "Illegal unquoted character ("+_getCharDesc(c)+"): has to be escaped using backslash to be included in "+ctxtDesc;
1027+
_reportError(msg);
1028+
}
1029+
}
1030+
10011031
/*
10021032
/**********************************************************
10031033
/* Base64 handling support

src/main/java/com/fasterxml/jackson/core/base/ParserMinimalBase.java

-28
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.math.BigInteger;
66

77
import com.fasterxml.jackson.core.*;
8-
import com.fasterxml.jackson.core.JsonParser.Feature;
98
import com.fasterxml.jackson.core.io.JsonEOFException;
109
import com.fasterxml.jackson.core.io.NumberInput;
1110
import com.fasterxml.jackson.core.util.ByteArrayBuilder;
@@ -620,33 +619,6 @@ protected void _throwInvalidSpace(int i) throws JsonParseException {
620619
_reportError(msg);
621620
}
622621

623-
/**
624-
* Method called to report a problem with unquoted control character.
625-
* Note: starting with version 1.4, it is possible to suppress
626-
* exception by enabling {@link Feature#ALLOW_UNQUOTED_CONTROL_CHARS}.
627-
*/
628-
protected void _throwUnquotedSpace(int i, String ctxtDesc) throws JsonParseException {
629-
// JACKSON-208; possible to allow unquoted control chars:
630-
if (!isEnabled(Feature.ALLOW_UNQUOTED_CONTROL_CHARS) || i > INT_SPACE) {
631-
char c = (char) i;
632-
String msg = "Illegal unquoted character ("+_getCharDesc(c)+"): has to be escaped using backslash to be included in "+ctxtDesc;
633-
_reportError(msg);
634-
}
635-
}
636-
637-
protected char _handleUnrecognizedCharacterEscape(char ch) throws JsonProcessingException {
638-
// as per [JACKSON-300]
639-
if (isEnabled(Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER)) {
640-
return ch;
641-
}
642-
// and [JACKSON-548]
643-
if (ch == '\'' && isEnabled(Feature.ALLOW_SINGLE_QUOTES)) {
644-
return ch;
645-
}
646-
_reportError("Unrecognized character escape "+_getCharDesc(ch));
647-
return ch;
648-
}
649-
650622
/*
651623
/**********************************************************
652624
/* Error reporting, generic

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

+2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ public enum JsonReadFeature
7777
* Since JSON specification requires quoting for all control characters,
7878
* this is a non-standard feature, and as such disabled by default.
7979
*/
80+
@SuppressWarnings("deprecation")
8081
ALLOW_UNESCAPED_CONTROL_CHARS(false, JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS),
8182

8283
/**
@@ -88,6 +89,7 @@ public enum JsonReadFeature
8889
* Since JSON specification requires quoting for all control characters,
8990
* this is a non-standard feature, and as such disabled by default.
9091
*/
92+
@SuppressWarnings("deprecation")
9193
ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER(false, JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER),
9294

9395
// // // Support for non-standard data format constructs: number representations

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ public class ReaderBasedJsonParser // final in 2.3, earlier
2525
@SuppressWarnings("deprecation")
2626
private final static int FEAT_MASK_LEADING_ZEROS = Feature.ALLOW_NUMERIC_LEADING_ZEROS.getMask();
2727

28+
@SuppressWarnings("deprecation")
29+
private final static int FEAT_MASK_NON_NUM_NUMBERS = Feature.ALLOW_NON_NUMERIC_NUMBERS.getMask();
30+
2831
// Latin1 encoding is not supported, but we do use 8-bit subset for
2932
// pre-processing task, to simplify first pass, keep it fast.
3033
protected final static int[] _icLatin1 = CharTypes.getInputCodeLatin1();
@@ -1616,14 +1619,14 @@ protected JsonToken _handleInvalidNumberStart(int ch, boolean negative) throws I
16161619
if (ch == 'N') {
16171620
String match = negative ? "-INF" :"+INF";
16181621
_matchToken(match, 3);
1619-
if (isEnabled(Feature.ALLOW_NON_NUMERIC_NUMBERS)) {
1622+
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
16201623
return resetAsNaN(match, negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY);
16211624
}
16221625
_reportError("Non-standard token '"+match+"': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
16231626
} else if (ch == 'n') {
16241627
String match = negative ? "-Infinity" :"+Infinity";
16251628
_matchToken(match, 3);
1626-
if (isEnabled(Feature.ALLOW_NON_NUMERIC_NUMBERS)) {
1629+
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
16271630
return resetAsNaN(match, negative ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY);
16281631
}
16291632
_reportError("Non-standard token '"+match+"': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
@@ -1869,14 +1872,14 @@ protected JsonToken _handleOddValue(int i) throws IOException
18691872
break;
18701873
case 'N':
18711874
_matchToken("NaN", 1);
1872-
if (isEnabled(Feature.ALLOW_NON_NUMERIC_NUMBERS)) {
1875+
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
18731876
return resetAsNaN("NaN", Double.NaN);
18741877
}
18751878
_reportError("Non-standard token 'NaN': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
18761879
break;
18771880
case 'I':
18781881
_matchToken("Infinity", 1);
1879-
if (isEnabled(Feature.ALLOW_NON_NUMERIC_NUMBERS)) {
1882+
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
18801883
return resetAsNaN("Infinity", Double.POSITIVE_INFINITY);
18811884
}
18821885
_reportError("Non-standard token 'Infinity': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public class UTF8DataInputJsonParser
4141
private final static int FEAT_MASK_TRAILING_COMMA = Feature.ALLOW_TRAILING_COMMA.getMask();
4242
@SuppressWarnings("deprecation")
4343
private final static int FEAT_MASK_LEADING_ZEROS = Feature.ALLOW_NUMERIC_LEADING_ZEROS.getMask();
44+
@SuppressWarnings("deprecation")
45+
private final static int FEAT_MASK_NON_NUM_NUMBERS = Feature.ALLOW_NON_NUMERIC_NUMBERS.getMask();
4446

4547
// This is the main input-code lookup table, fetched eagerly
4648
private final static int[] _icUTF8 = CharTypes.getInputCodeUtf8();
@@ -2030,14 +2032,14 @@ protected JsonToken _handleUnexpectedValue(int c)
20302032
break;
20312033
case 'N':
20322034
_matchToken("NaN", 1);
2033-
if (isEnabled(Feature.ALLOW_NON_NUMERIC_NUMBERS)) {
2035+
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
20342036
return resetAsNaN("NaN", Double.NaN);
20352037
}
20362038
_reportError("Non-standard token 'NaN': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
20372039
break;
20382040
case 'I':
20392041
_matchToken("Infinity", 1);
2040-
if (isEnabled(Feature.ALLOW_NON_NUMERIC_NUMBERS)) {
2042+
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
20412043
return resetAsNaN("Infinity", Double.POSITIVE_INFINITY);
20422044
}
20432045
_reportError("Non-standard token 'Infinity': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
@@ -2145,7 +2147,7 @@ protected JsonToken _handleInvalidNumberStart(int ch, boolean neg)
21452147
break;
21462148
}
21472149
_matchToken(match, 3);
2148-
if (isEnabled(Feature.ALLOW_NON_NUMERIC_NUMBERS)) {
2150+
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
21492151
return resetAsNaN(match, neg ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY);
21502152
}
21512153
_reportError("Non-standard token '"+match+"': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class UTF8StreamJsonParser
2424
private final static int FEAT_MASK_TRAILING_COMMA = Feature.ALLOW_TRAILING_COMMA.getMask();
2525
@SuppressWarnings("deprecation")
2626
private final static int FEAT_MASK_LEADING_ZEROS = Feature.ALLOW_NUMERIC_LEADING_ZEROS.getMask();
27+
@SuppressWarnings("deprecation")
28+
private final static int FEAT_MASK_NON_NUM_NUMBERS = Feature.ALLOW_NON_NUMERIC_NUMBERS.getMask();
2729

2830
// This is the main input-code lookup table, fetched eagerly
2931
private final static int[] _icUTF8 = CharTypes.getInputCodeUtf8();
@@ -2597,14 +2599,14 @@ protected JsonToken _handleUnexpectedValue(int c) throws IOException
25972599
break;
25982600
case 'N':
25992601
_matchToken("NaN", 1);
2600-
if (isEnabled(Feature.ALLOW_NON_NUMERIC_NUMBERS)) {
2602+
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
26012603
return resetAsNaN("NaN", Double.NaN);
26022604
}
26032605
_reportError("Non-standard token 'NaN': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
26042606
break;
26052607
case 'I':
26062608
_matchToken("Infinity", 1);
2607-
if (isEnabled(Feature.ALLOW_NON_NUMERIC_NUMBERS)) {
2609+
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
26082610
return resetAsNaN("Infinity", Double.POSITIVE_INFINITY);
26092611
}
26102612
_reportError("Non-standard token 'Infinity': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow");
@@ -2743,7 +2745,7 @@ protected JsonToken _handleInvalidNumberStart(int ch, boolean neg) throws IOExce
27432745
break;
27442746
}
27452747
_matchToken(match, 3);
2746-
if (isEnabled(Feature.ALLOW_NON_NUMERIC_NUMBERS)) {
2748+
if ((_features & FEAT_MASK_NON_NUM_NUMBERS) != 0) {
27472749
return resetAsNaN(match, neg ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY);
27482750
}
27492751
_reportError("Non-standard token '%s': enable JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS to allow",

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

+1
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,7 @@ protected final JsonToken _valueCompleteInt(int value, String asText) throws IOE
836836
return t;
837837
}
838838

839+
@SuppressWarnings("deprecation")
839840
protected final JsonToken _valueNonStdNumberComplete(int type) throws IOException
840841
{
841842
String tokenStr = NON_STD_TOKENS[type];

src/test/java/com/fasterxml/jackson/core/json/async/AsyncNonStdParsingTest.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.fasterxml.jackson.core.*;
66
import com.fasterxml.jackson.core.async.AsyncTestBase;
7+
import com.fasterxml.jackson.core.json.JsonReadFeature;
78
import com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper;
89

910
public class AsyncNonStdParsingTest extends AsyncTestBase
@@ -360,7 +361,6 @@ private void _testNonStandarBackslashQuoting(
360361
{
361362
// first: verify that we get an exception
362363
JsonFactory f = new JsonFactory();
363-
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
364364
final String JSON = quote("\\'");
365365
AsyncReaderWrapper p = createParser(f, JSON, offset, readSize);
366366
try {
@@ -373,8 +373,9 @@ private void _testNonStandarBackslashQuoting(
373373
p.close();
374374
}
375375
// and then verify it's ok...
376-
f.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true);
377-
assertTrue(f.isEnabled(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
376+
f = f.rebuild()
377+
.enable(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER)
378+
.build();
378379
p = createParser(f, JSON, offset, readSize);
379380
assertToken(JsonToken.VALUE_STRING, p.nextToken());
380381
assertEquals("'", p.currentText());

src/test/java/com/fasterxml/jackson/core/main/TestParserFeatures.java

+12-5
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ public void testDefaultSettings() throws Exception
1616
JsonFactory f = new JsonFactory();
1717
assertTrue(f.isEnabled(JsonParser.Feature.AUTO_CLOSE_SOURCE));
1818
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_COMMENTS));
19-
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES));
20-
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_SINGLE_QUOTES));
21-
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS));
2219

2320
JsonParser p = f.createParser(new StringReader("{}"));
2421
_testDefaultSettings(p);
@@ -28,6 +25,15 @@ public void testDefaultSettings() throws Exception
2825
p.close();
2926
}
3027

28+
@SuppressWarnings("deprecation")
29+
public void testDeprecatedDefaultSettings() throws Exception
30+
{
31+
JsonFactory f = new JsonFactory();
32+
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS));
33+
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES));
34+
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_SINGLE_QUOTES));
35+
}
36+
3137
public void testQuotesRequired() throws Exception
3238
{
3339
_testQuotesRequired(false);
@@ -101,8 +107,9 @@ private void _testTabsDefault(boolean useStream) throws Exception
101107

102108
private void _testTabsEnabled(boolean useStream) throws Exception
103109
{
104-
JsonFactory f = new JsonFactory();
105-
f.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
110+
JsonFactory f = JsonFactory.builder()
111+
.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true)
112+
.build();
106113

107114
String FIELD = "a\tb";
108115
String VALUE = "\t";

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,6 @@ private void _testNonStandarBackslashQuoting(int mode) throws Exception
362362
{
363363
// first: verify that we get an exception
364364
JsonFactory f = new JsonFactory();
365-
assertFalse(f.isEnabled(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
366365
final String JSON = quote("\\'");
367366
JsonParser p = createParser(f, mode, JSON);
368367
try {
@@ -375,8 +374,9 @@ private void _testNonStandarBackslashQuoting(int mode) throws Exception
375374
p.close();
376375
}
377376
// and then verify it's ok...
378-
f.configure(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true);
379-
assertTrue(f.isEnabled(JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER));
377+
f = f.rebuild()
378+
.configure(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER, true)
379+
.build();
380380
p = createParser(f, mode, JSON);
381381
assertToken(JsonToken.VALUE_STRING, p.nextToken());
382382
assertEquals("'", p.getText());

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

+4-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.math.BigInteger;
88

99
import com.fasterxml.jackson.core.*;
10+
import com.fasterxml.jackson.core.json.JsonReadFeature;
1011

1112
/**
1213
* Set of basic unit tests for verifying that the basic parser
@@ -461,8 +462,9 @@ private void _testIssue160LongNumbers(JsonFactory f, String doc, boolean useStre
461462
*/
462463
public void testParsingOfLongerSequencesWithNonNumeric() throws Exception
463464
{
464-
JsonFactory f = new JsonFactory();
465-
f.enable(JsonParser.Feature.ALLOW_NON_NUMERIC_NUMBERS);
465+
JsonFactory f = JsonFactory.builder()
466+
.enable(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS)
467+
.build();
466468
_testParsingOfLongerSequencesWithNonNumeric(f, MODE_INPUT_STREAM);
467469
_testParsingOfLongerSequencesWithNonNumeric(f, MODE_INPUT_STREAM_THROTTLED);
468470
_testParsingOfLongerSequencesWithNonNumeric(f, MODE_READER);

0 commit comments

Comments
 (0)