Skip to content

Commit

Permalink
Ignore empty completion input
Browse files Browse the repository at this point in the history
This change makes sure that an empty completion input does not throw an IAE when indexing.
Instead the input is simply ignored.

Closes elastic#23121
  • Loading branch information
jimczi committed Jan 18, 2018
1 parent 06f931f commit f7a6496
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,10 @@ public Mapper parse(ParseContext context) throws IOException {
}
input = input.substring(0, len);
}
if (input.length() == 0) {
// Ignore empty inputs
continue;
}
CompletionInputMetaData metaData = completionInput.getValue();
if (fieldType().hasContextMappings()) {
fieldType().getContextMappings().addField(context.doc(), fieldType().name(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,16 @@ public void testFieldValueValidation() throws Exception {
assertThat(cause, instanceOf(IllegalArgumentException.class));
assertThat(cause.getMessage(), containsString("[0x1e]"));
}

// empty inputs are ignored
ParsedDocument doc = defaultMapper.parse(SourceToParse.source("test", "type1", "1", XContentFactory.jsonBuilder()
.startObject()
.field("completion", "")
.endObject()
.bytes(),
XContentType.JSON));
assertThat(doc.docs().size(), equalTo(1));
assertNull(doc.docs().get(0).get("completion"));
}

public void testPrefixQueryType() throws Exception {
Expand Down

0 comments on commit f7a6496

Please sign in to comment.