use of org.apache.lucene.util.CharsRefBuilder in project elasticsearch by elastic.
the class CompletionFieldMapperTests method testFieldValueValidation.
public void testFieldValueValidation() throws Exception {
String mapping = jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("completion").field("type", "completion").endObject().endObject().endObject().endObject().string();
DocumentMapper defaultMapper = createIndex("test").mapperService().documentMapperParser().parse("type1", new CompressedXContent(mapping));
CharsRefBuilder charsRefBuilder = new CharsRefBuilder();
charsRefBuilder.append("sugg");
charsRefBuilder.setCharAt(2, '');
try {
defaultMapper.parse("test", "type1", "1", XContentFactory.jsonBuilder().startObject().field("completion", charsRefBuilder.get().toString()).endObject().bytes());
fail("No error indexing value with reserved character [0x1F]");
} catch (MapperParsingException e) {
Throwable cause = e.unwrapCause().getCause();
assertThat(cause, instanceOf(IllegalArgumentException.class));
assertThat(cause.getMessage(), containsString("[0x1f]"));
}
charsRefBuilder.setCharAt(2, '