-
-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
src/test/java/com/fasterxml/jackson/core/read/TestLargeString.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,48 @@ | ||
package com.fasterxml.jackson.core.read; | ||
|
||
import com.fasterxml.jackson.core.JUnit5TestBase; | ||
import com.fasterxml.jackson.core.JsonFactory; | ||
import com.fasterxml.jackson.core.JsonParser; | ||
import com.fasterxml.jackson.core.StreamReadConstraints; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
// https://github.com/FasterXML/jackson-core/pull/1350 | ||
class TestLargeString extends JUnit5TestBase { | ||
|
||
// disabled because it takes too much memory to run | ||
@Disabled | ||
@Test | ||
void testLargeStringDeserialization() throws Exception { | ||
final int len = Integer.MAX_VALUE - 1024; | ||
final byte[] largeByteString = makeLongByteString(len); | ||
final JsonFactory f = JsonFactory.builder() | ||
.streamReadConstraints(StreamReadConstraints.builder() | ||
.maxStringLength(Integer.MAX_VALUE) | ||
.build()) | ||
.build(); | ||
|
||
try (JsonParser parser = f.createParser(largeByteString)) { | ||
final String parsedString = parser.nextTextValue(); | ||
assertEquals(len, parsedString.length()); | ||
for (int i = 0; i < len; i++) { | ||
assertEquals('a', parsedString.charAt(i)); | ||
} | ||
} | ||
|
||
} | ||
|
||
private byte[] makeLongByteString(int length) { | ||
final byte[] result = new byte[length + 2]; | ||
final byte b = 'a'; | ||
final int last = length + 1; | ||
result[0] = '\"'; | ||
for (int i = 1; i < last; i++) { | ||
result[i] = b; | ||
} | ||
result[last] = result[0]; | ||
return result; | ||
} | ||
} |