Skip to content

Commit

Permalink
Create TestLargeString.java
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Oct 27, 2024
1 parent 38cc2ed commit 39ece30
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/test/java/com/fasterxml/jackson/core/read/TestLargeString.java
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;
}
}

0 comments on commit 39ece30

Please sign in to comment.