Skip to content

Commit

Permalink
Added test for deep nested object and array combination
Browse files Browse the repository at this point in the history
Fixing the issue (#5195)

Signed-off-by: Nikhil Kumar <nikhkumn@amazon.com>
  • Loading branch information
Nikhil Kumar committed Jan 5, 2023
1 parent 8f09be5 commit 2c6c8b9
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1597,4 +1597,45 @@ public void testDocumentContainsDeepNestedFieldParsingShouldFail() throws Except
assertNotNull(update); // dynamic mapping update

}

// Test nesting upto max allowed depth with combination of nesting in object and array
// object -> array -> object -> array ....
public void testDocumentDeepNestedObjectAndArrayCombination() throws Exception {
DocumentMapper mapper = createDocumentMapper(mapping(b -> {}));
long depth_limit = MapperService.INDEX_MAPPING_DEPTH_LIMIT_SETTING.getDefault(Settings.EMPTY);
MapperParsingException e = expectThrows(MapperParsingException.class, () -> mapper.parse(source(b -> {
for (int i = 1; i < depth_limit; i++) {
b.startArray("foo" + 1);
b.startObject();
}
b.startArray("bar");
b.startArray().value(0).value(0).endArray();
b.endArray();
for (int i = 1; i < depth_limit; i++) {
b.endObject();
b.endArray();
}
})));

// check parsing success for nested array within allowed depth limit
ParsedDocument doc = mapper.parse(source(b -> {
for (int i = 1; i < depth_limit - 1; i++) {
b.startArray("foo" + 1);
b.startObject();
}
b.startArray("bar");
b.startArray().value(0).value(0).endArray();
b.endArray();
for (int i = 1; i < depth_limit - 1; i++) {
b.endObject();
b.endArray();
}
}

));
Mapping update = doc.dynamicMappingsUpdate();
assertNotNull(update); // dynamic mapping update

}

}

0 comments on commit 2c6c8b9

Please sign in to comment.