Skip to content

Commit

Permalink
Handles the status code for . properties (opensearch-project#4246) (o…
Browse files Browse the repository at this point in the history
…pensearch-project#4251)

* Return 400 status code for array out of bound

Signed-off-by: Owais Kazi <owaiskazi19@gmail.com>

* Spotless apply

Signed-off-by: Owais Kazi <owaiskazi19@gmail.com>

* PR comments

Signed-off-by: Owais Kazi <owaiskazi19@gmail.com>

Signed-off-by: Owais Kazi <owaiskazi19@gmail.com>
(cherry picked from commit 36f1d77)

Co-authored-by: Owais Kazi <owaiskazi19@gmail.com>
  • Loading branch information
opensearch-trigger-bot[bot] and owaiskazi19 authored Aug 18, 2022
1 parent 397f1eb commit fafdd28
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 fafdd28

Please sign in to comment.