Skip to content

Commit

Permalink
Fixes #745: increase max array length limit to 1,000 (from 100) (#770)
Browse files Browse the repository at this point in the history
  • Loading branch information
tatu-at-datastax authored Jan 5, 2024
1 parent d86678e commit cdc94f4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/jsonapi-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ The maximum size of field values are:

#### Document Array Limits

The maximum length of an array is 100 elements.
The maximum length of an array is 1,000 elements.

### Equality handling with arrays and subdocs

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public interface DocumentLimitsConfig {
int DEFAULT_MAX_DOCUMENT_SIZE = 1_000_000;

/** Defines the default maximum length (in elements) of a single Array value */
int DEFAULT_MAX_ARRAY_LENGTH = 100;
int DEFAULT_MAX_ARRAY_LENGTH = 1_000;

/**
* Defines the default maximum number of properties any single Object in JSON document can contain
Expand Down Expand Up @@ -118,7 +118,7 @@ public interface DocumentLimitsConfig {
@WithDefault("" + DEFAULT_MAX_STRING_LENGTH_IN_BYTES)
int maxStringLengthInBytes();

/** @return Maximum length of an array. */
/** @return Maximum length of an Array in document, defaults to {@code 1,000} elements. */
@Positive
@WithDefault("" + DEFAULT_MAX_ARRAY_LENGTH)
int maxArrayLength();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ public void insertBiggestValidArray() {

@Test
public void tryInsertTooBigArray() {
// Max array elements allowed is 100; add a few more
// Max array elements allowed is 1000; add a few more
ObjectNode doc = MAPPER.createObjectNode();
ArrayNode arr = doc.putArray("arr");
final int ARRAY_LEN = MAX_ARRAY_LENGTH + 10;
Expand Down Expand Up @@ -561,7 +561,9 @@ public void tryInsertTooBigArray() {
is(
"Document size limitation violated: number of elements an Array has ("
+ ARRAY_LEN
+ ") exceeds maximum allowed (100)"));
+ ") exceeds maximum allowed ("
+ MAX_ARRAY_LENGTH
+ ")"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,23 +175,25 @@ private ObjectNode docWithNestedProps(int rootCount, int leafCount) {

@Test
public void allowDocWithManyArrayElements() {
// Max allowed 100, add 90
final ObjectNode doc = docWithNArrayElems("arr", 90);
// Max allowed 1000, test:
final ObjectNode doc = docWithNArrayElems("arr", docLimits.maxArrayLength());
assertThat(shredder.shred(doc)).isNotNull();
}

@Test
public void catchTooManyArrayElements() {
// Let's add 120 elements (max allowed: 100)
final ObjectNode doc = docWithNArrayElems("arr", 120);
final int arraySizeAboveMax = docLimits.maxArrayLength() + 1;
final ObjectNode doc = docWithNArrayElems("arr", arraySizeAboveMax);
Exception e = catchException(() -> shredder.shred(doc));
assertThat(e)
.isNotNull()
.isInstanceOf(JsonApiException.class)
.hasFieldOrPropertyWithValue("errorCode", ErrorCode.SHRED_DOC_LIMIT_VIOLATION)
.hasMessageStartingWith(ErrorCode.SHRED_DOC_LIMIT_VIOLATION.getMessage())
.hasMessageEndingWith(
" number of elements an Array has (120) exceeds maximum allowed ("
" number of elements an Array has ("
+ arraySizeAboveMax
+ ") exceeds maximum allowed ("
+ docLimits.maxArrayLength()
+ ")");
}
Expand Down

0 comments on commit cdc94f4

Please sign in to comment.