Skip to content

Commit baf8cbf

Browse files
owaiskazi19github-actions[bot]
authored andcommitted
Handles the status code for . properties (#4246)
* 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)
1 parent 397f1eb commit baf8cbf

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

server/src/main/java/org/opensearch/index/mapper/ObjectMapper.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ protected static void parseProperties(ObjectMapper.Builder objBuilder, Map<Strin
380380
throw new MapperParsingException("No handler for type [" + type + "] declared on field [" + fieldName + "]");
381381
}
382382
String[] fieldNameParts = fieldName.split("\\.");
383+
// field name is just ".", which is invalid
384+
if (fieldNameParts.length < 1) {
385+
throw new MapperParsingException("Invalid field name " + fieldName);
386+
}
383387
String realFieldName = fieldNameParts[fieldNameParts.length - 1];
384388
Mapper.Builder<?> fieldBuilder = typeParser.parse(realFieldName, propNode, parserContext);
385389
for (int i = fieldNameParts.length - 2; i >= 0; --i) {

server/src/test/java/org/opensearch/index/mapper/ObjectMapperTests.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,26 @@ public void testFieldsWithFilledArrayShouldThrowException() throws Exception {
178178
}
179179
}
180180

181+
public void testDotAsFieldName() throws Exception {
182+
String mapping = Strings.toString(
183+
XContentFactory.jsonBuilder()
184+
.startObject()
185+
.startObject("properties")
186+
.startObject(".")
187+
.field("type", "text")
188+
.endObject()
189+
.endObject()
190+
.endObject()
191+
);
192+
193+
try {
194+
createIndex("test").mapperService().documentMapperParser().parse("tweet", new CompressedXContent(mapping));
195+
fail("Expected MapperParsingException");
196+
} catch (MapperParsingException e) {
197+
assertThat(e.getMessage(), containsString("Invalid field name"));
198+
}
199+
}
200+
181201
public void testFieldPropertiesArray() throws Exception {
182202
String mapping = Strings.toString(
183203
XContentFactory.jsonBuilder()

0 commit comments

Comments
 (0)