-
-
Notifications
You must be signed in to change notification settings - Fork 812
Skip RS CTRL-CHAR to support JSON Text Sequence (RFC7464) #1414
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
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d8af680
Skipping \u001E for readerBased parser and adding base feature
iifawzi ec511d8
Fixing broken tests and handle UTF8 Stream Parser
iifawzi 69e6af6
Adapting NonBlocking Utf8JsonParse for record separation tokens
iifawzi a943ec9
improving comments
iifawzi 28fe3d4
improve fail message pointing to the feature
iifawzi b194ccc
remove unused mask
iifawzi d2ceca9
updating version
iifawzi 8b06976
improve fail message
iifawzi 7e864a2
Minor clean up
cowtowncoder dd928b1
Bit of test refactoring
cowtowncoder f3e1264
Update release notes
cowtowncoder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/test/java/com/fasterxml/jackson/core/read/NonStandardAllowRSTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.fasterxml.jackson.core.read; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import java.io.StringReader; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.fasterxml.jackson.core.*; | ||
import com.fasterxml.jackson.core.exc.StreamReadException; | ||
import com.fasterxml.jackson.core.json.JsonReadFeature; | ||
import com.fasterxml.jackson.core.json.async.NonBlockingJsonParser; | ||
|
||
// for [core#633]: optionally allow Record-Separator ctrl char | ||
class NonStandardAllowRSTest | ||
extends JUnit5TestBase | ||
{ | ||
@Test | ||
void recordSeparatorEnabled() throws Exception { | ||
doRecordSeparationTest(true); | ||
} | ||
|
||
@Test | ||
void recordSeparatorDisabled() throws Exception { | ||
doRecordSeparationTest(false); | ||
} | ||
|
||
// Testing record separation for all parser implementations | ||
private void doRecordSeparationTest(boolean recordSeparation) throws Exception { | ||
String contents = "{\"key\":true}\u001E"; | ||
JsonFactory factory = JsonFactory.builder() | ||
.configure(JsonReadFeature.ALLOW_RS_CONTROL_CHAR, recordSeparation) | ||
.build(); | ||
try (JsonParser parser = factory.createParser(contents)) { | ||
verifyRecordSeparation(parser, recordSeparation); | ||
} | ||
try (JsonParser parser = factory.createParser(new StringReader(contents))) { | ||
verifyRecordSeparation(parser, recordSeparation); | ||
} | ||
try (JsonParser parser = factory.createParser(contents.getBytes(StandardCharsets.UTF_8))) { | ||
verifyRecordSeparation(parser, recordSeparation); | ||
} | ||
try (NonBlockingJsonParser parser = (NonBlockingJsonParser) factory.createNonBlockingByteArrayParser()) { | ||
byte[] data = contents.getBytes(StandardCharsets.UTF_8); | ||
parser.feedInput(data, 0, data.length); | ||
parser.endOfInput(); | ||
verifyRecordSeparation(parser, recordSeparation); | ||
} | ||
} | ||
|
||
private void verifyRecordSeparation(JsonParser parser, boolean recordSeparation) throws Exception { | ||
try { | ||
assertToken(JsonToken.START_OBJECT, parser.nextToken()); | ||
String field1 = parser.nextFieldName(); | ||
assertEquals("key", field1); | ||
assertToken(JsonToken.VALUE_TRUE, parser.nextToken()); | ||
assertToken(JsonToken.END_OBJECT, parser.nextToken()); | ||
parser.nextToken(); // RS token | ||
if (!recordSeparation) { | ||
fail("Should have thrown an exception"); | ||
} | ||
} catch (StreamReadException e) { | ||
if (!recordSeparation) { | ||
verifyException(e, "Illegal character ((CTRL-CHAR"); | ||
verifyException(e, "consider enabling `JsonReadFeature.ALLOW_RS_CONTROL_CHAR`"); | ||
} else { | ||
throw e; | ||
} | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May look funny but
JsonParser.Feature
is to be removed from 3.0 yet is needed internally (allStreamReadFeature
s andJsonReadFeature
s must map back to one entry).But we don't want users to use
JsonParser.Feature
any more.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's good to know about that to help take care of it next time.
Thanks for your collaboration on the PRs!