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 1 commit
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
14 changes: 14 additions & 0 deletions src/main/java/com/fasterxml/jackson/core/JsonParser.java
Expand Up @@ -138,6 +138,20 @@ public enum Feature {
*/
ALLOW_SINGLE_QUOTES(false),

/**
* Feature that determines whether parser will allow use
* of the RS control character (exhibited by 0x1E and parsed as a
* tab or /t) within parsed content or not.
*<p>
* Since JSON specification requires use of double quotes for
cowtowncoder marked this conversation as resolved.
Show resolved Hide resolved
* field names,
* this is a non-standard feature, and as such disabled by default.
*<p>
* NOTE: while not technically deprecated, since 2.10 recommended to use
* {@link com.fasterxml.jackson.core.json.JsonReadFeature#ALLOW_SINGLE_QUOTES} instead.
*/
ALLOW_RS_CONTROL_CHAR(false),

/**
* Feature that determines whether parser will allow
* JSON Strings to contain unquoted control characters
Expand Down
Expand Up @@ -29,6 +29,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
15 changes: 15 additions & 0 deletions src/main/java/com/fasterxml/jackson/core/json/JsonReadFeature.java
Expand Up @@ -11,6 +11,21 @@
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 (exhibited by 0x1E and parsed as a
* tab or /t) within parsed content or not.
*<p>
* Since JSON specification does not mention comments as legal
* construct,
* this is a non-standard feature. As such, feature is
* <b>disabled by default</b> for parsers and must be
* explicitly enabled.
*/
ALLOW_RS_CONTROL_CHAR(false, JsonParser.Feature.ALLOW_RS_CONTROL_CHAR),

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

/**
Expand Down
Expand Up @@ -35,6 +35,8 @@ public class ReaderBasedJsonParser

private final static int FEAT_MASK_ALLOW_JAVA_COMMENTS = Feature.ALLOW_COMMENTS.getMask();
private final static int FEAT_MASK_ALLOW_YAML_COMMENTS = Feature.ALLOW_YAML_COMMENTS.getMask();

private final static int FEAT_MASK_ALLOW_CONTROL_CHAR = Feature.ALLOW_RS_CONTROL_CHAR.getMask();

// Latin1 encoding is not supported, but we do use 8-bit subset for
// pre-processing task, to simplify first pass, keep it fast.
Expand Down Expand Up @@ -2538,8 +2540,8 @@ private final int _skipWSOrEnd() throws IOException
_currInputRowStart = _inputPtr;
} else if (i == INT_CR) {
_skipCR();
} else if (i != INT_TAB) {
_throwInvalidSpace(i);
} else if (i != INT_TAB && ((_features & FEAT_MASK_ALLOW_CONTROL_CHAR) != 0 && i != INT_RS)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think latter && needs to be || (so failure if Not Tab and either Don't Allow RS OR not RS).
Otherwise fails some unit tests on CI (see failures)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

_throwInvalidSpace(i);
}
}

Expand All @@ -2558,7 +2560,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_CONTROL_CHAR) != 0 && i != INT_RS)) {
_throwInvalidSpace(i);
}
}
Expand Down
Expand Up @@ -387,4 +387,5 @@ private AsyncReaderWrapper createParser(JsonFactory f, String doc,
{
return asyncForBytes(f, readSize, _jsonDoc(doc), offset);
}

}