Skip to content

Commit

Permalink
Backport Return 400 status code for array out of bound (#6359)
Browse files Browse the repository at this point in the history
Signed-off-by: owaiskazi19 <owaiskazi19@gmail.com>
  • Loading branch information
owaiskazi19 authored Feb 21, 2023
1 parent b77a827 commit a3a99b8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ protected static void parseProperties(ObjectMapper.Builder objBuilder, Map<Strin
throw new MapperParsingException("No handler for type [" + type + "] declared on field [" + fieldName + "]");
}
String[] fieldNameParts = fieldName.split("\\.");
// field name is just ".", which is invalid
if (fieldNameParts.length < 1) {
throw new MapperParsingException("Invalid field name " + fieldName);
}
String realFieldName = fieldNameParts[fieldNameParts.length - 1];
Mapper.Builder<?> fieldBuilder = typeParser.parse(realFieldName, propNode, parserContext);
for (int i = fieldNameParts.length - 2; i >= 0; --i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,26 @@ public void testFieldsWithFilledArrayShouldThrowException() throws Exception {
}
}

public void testDotAsFieldName() throws Exception {
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject(".")
.field("type", "text")
.endObject()
.endObject()
.endObject()
);

try {
createIndex("test").mapperService().documentMapperParser().parse("tweet", new CompressedXContent(mapping));
fail("Expected MapperParsingException");
} catch (MapperParsingException e) {
assertThat(e.getMessage(), containsString("Invalid field name"));
}
}

public void testFieldPropertiesArray() throws Exception {
String mapping = Strings.toString(
XContentFactory.jsonBuilder()
Expand Down

0 comments on commit a3a99b8

Please sign in to comment.