Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding feature to allow for skipping RS control char #633 #1155

Open
wants to merge 6 commits into
base: 2.18
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/main/java/com/fasterxml/jackson/core/JsonParser.java
Expand Up @@ -177,6 +177,23 @@ public enum Feature {
*/
ALLOW_SINGLE_QUOTES(false),

/**
* Feature that determines whether parser will allow use
* of the RS control character ({@code 0x1E}) within ignorable
* whitespace portion of input content (similar to TAB which
* is an allowed control character).
*<p>
* Since JSON specification only allows a small set of control characters
* as whitespace by default,
* this is a non-standard feature, and as such disabled by default.
*<p>
* NOTE: while not technically deprecated, it is recommended to use
* {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_RS_CONTROL_CHAR} instead.
*
* @since 2.17
*/
ALLOW_RS_CONTROL_CHAR(false),

/**
* Feature that determines whether parser will allow
* JSON Strings to contain unquoted control characters
Expand Down
Expand Up @@ -30,6 +30,7 @@ public abstract class ParserMinimalBase extends JsonParser
protected final static int INT_LF = '\n';
protected final static int INT_CR = '\r';
protected final static int INT_SPACE = 0x0020;
protected final static int INT_RS = 0x001E;

// Markup
protected final static int INT_LBRACKET = '[';
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/fasterxml/jackson/core/json/JsonReadFeature.java
Expand Up @@ -11,6 +11,22 @@
public enum JsonReadFeature
implements FormatFeature
{
// // // Support for non-standard data format constructs: whitespaces

/**
* Feature that determines whether parser will allow use
* of the RS control character ({@code 0x1E}) within ignorable
* whitespace portion of input content (similar to TAB which
* is an allowed control character).
*<p>
* Since JSON specification only allows a small set of control characters
* as whitespace by default,
* this is a non-standard feature, and as such disabled by default.
*
* @since 2.17
*/
ALLOW_RS_CONTROL_CHAR(false, JsonParser.Feature.ALLOW_RS_CONTROL_CHAR),

// // // Support for non-standard data format constructs: comments

/**
Expand Down
Expand Up @@ -2505,7 +2505,8 @@ private final int _skipWSOrEnd() throws IOException
_currInputRowStart = _inputPtr;
} else if (i == INT_CR) {
_skipCR();
} else if (i != INT_TAB) {
} else if (i != INT_TAB
&& ((_features & FEAT_MASK_ALLOW_RS_CTRL_CHAR) == 0 || i != INT_RS)) {
_throwInvalidSpace(i);
}
}
Expand All @@ -2525,7 +2526,7 @@ private final int _skipWSOrEnd() throws IOException
_currInputRowStart = _inputPtr;
} else if (i == INT_CR) {
_skipCR();
} else if (i != INT_TAB) {
} else if (i != INT_TAB && ((_features & FEAT_MASK_ALLOW_RS_CTRL_CHAR) != 0 && i != INT_RS)) {
_throwInvalidSpace(i);
}
}
Expand Down
Expand Up @@ -400,4 +400,5 @@ private AsyncReaderWrapper createParser(JsonFactory f, String doc,
{
return asyncForBytes(f, readSize, _jsonDoc(doc), offset);
}

}