-
-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update release notes wrt #1047, minor tweaking
- Loading branch information
1 parent
bc8433b
commit e7ad6bb
Showing
8 changed files
with
123 additions
and
125 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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
84 changes: 84 additions & 0 deletions
84
src/test/java/com/fasterxml/jackson/core/constraints/LargeNameReadTest.java
This file contains 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,84 @@ | ||
package com.fasterxml.jackson.core.constraints; | ||
|
||
import java.io.IOException; | ||
|
||
import com.fasterxml.jackson.core.*; | ||
import com.fasterxml.jackson.core.StreamReadConstraints; | ||
import com.fasterxml.jackson.core.exc.StreamConstraintsException; | ||
import com.fasterxml.jackson.core.json.async.NonBlockingJsonParser; | ||
|
||
// [core#1047]: Add max-name-length constraints | ||
public class LargeNameReadTest extends BaseTest | ||
{ | ||
private final JsonFactory JSON_F_DEFAULT = newStreamFactory(); | ||
|
||
private final JsonFactory JSON_F_NAME_100 = JsonFactory.builder() | ||
.streamReadConstraints(StreamReadConstraints.builder().maxNameLength(100).build()) | ||
.build(); | ||
|
||
// Test name that is below default max name | ||
public void testLargeNameBytes() throws Exception { | ||
final String doc = generateJSON(StreamReadConstraints.defaults().getMaxNameLength() - 100); | ||
try (JsonParser p = createParserUsingStream(JSON_F_DEFAULT, doc, "UTF-8")) { | ||
consumeTokens(p); | ||
} | ||
} | ||
|
||
public void testLargeNameChars() throws Exception { | ||
final String doc = generateJSON(StreamReadConstraints.defaults().getMaxNameLength() - 100); | ||
try (JsonParser p = createParserUsingReader(JSON_F_DEFAULT, doc)) { | ||
consumeTokens(p); | ||
} | ||
} | ||
|
||
public void testLargeNameWithSmallLimitBytes() throws Exception | ||
{ | ||
final String doc = generateJSON(1000); | ||
try (JsonParser p = createParserUsingStream(JSON_F_NAME_100, doc, "UTF-8")) { | ||
consumeTokens(p); | ||
fail("expected StreamConstraintsException"); | ||
} catch (StreamConstraintsException e) { | ||
verifyException(e, "Name length"); | ||
} | ||
} | ||
|
||
public void testLargeNameWithSmallLimitCharss() throws Exception | ||
{ | ||
final String doc = generateJSON(1000); | ||
try (JsonParser p = createParserUsingReader(JSON_F_NAME_100, doc)) { | ||
consumeTokens(p); | ||
fail("expected StreamConstraintsException"); | ||
} catch (StreamConstraintsException e) { | ||
verifyException(e, "Name length"); | ||
} | ||
} | ||
|
||
public void testLargeNameWithSmallLimitAsync() throws Exception | ||
{ | ||
final byte[] doc = utf8Bytes(generateJSON(1000)); | ||
|
||
try (NonBlockingJsonParser p = (NonBlockingJsonParser) JSON_F_NAME_100.createNonBlockingByteArrayParser()) { | ||
p.feedInput(doc, 0, doc.length); | ||
consumeTokens(p); | ||
fail("expected StreamConstraintsException"); | ||
} catch (StreamConstraintsException e) { | ||
verifyException(e, "Name length"); | ||
} | ||
} | ||
|
||
private void consumeTokens(JsonParser p) throws IOException { | ||
while (p.nextToken() != null) { | ||
; | ||
} | ||
} | ||
|
||
private String generateJSON(final int nameLen) { | ||
final StringBuilder sb = new StringBuilder(); | ||
sb.append("{\""); | ||
for (int i = 0; i < nameLen; i++) { | ||
sb.append("a"); | ||
} | ||
sb.append("\":\"value\"}"); | ||
return sb.toString(); | ||
} | ||
} |
Oops, something went wrong.