Improve error msg when a field name contains only white spaces (#27709)
* Explicitly check if a field name contains only white spaces * "white spaces" changed to "whitespace"
This commit is contained in:
parent
b66a0721da
commit
f50f99ef11
|
@ -180,6 +180,11 @@ final class DocumentParser {
|
|||
String[] parts = fullFieldPath.split("\\.");
|
||||
for (String part : parts) {
|
||||
if (Strings.hasText(part) == false) {
|
||||
// check if the field name contains only whitespace
|
||||
if (Strings.isEmpty(part) == false) {
|
||||
throw new IllegalArgumentException(
|
||||
"object field cannot contain only whitespace: ['" + fullFieldPath + "']");
|
||||
}
|
||||
throw new IllegalArgumentException(
|
||||
"object field starting or ending with a [.] makes object resolution ambiguous: [" + fullFieldPath + "]");
|
||||
}
|
||||
|
|
|
@ -1377,6 +1377,23 @@ public class DocumentParserTests extends ESSingleNodeTestCase {
|
|||
}
|
||||
}
|
||||
|
||||
public void testDynamicFieldsEmptyName() throws Exception {
|
||||
BytesReference bytes = XContentFactory.jsonBuilder()
|
||||
.startObject().startArray("top.")
|
||||
.startObject()
|
||||
.startObject("aoeu")
|
||||
.field("a", 1).field(" ", 2)
|
||||
.endObject()
|
||||
.endObject().endArray()
|
||||
.endObject().bytes();
|
||||
|
||||
IllegalArgumentException emptyFieldNameException = expectThrows(IllegalArgumentException.class,
|
||||
() -> client().prepareIndex("idx", "type").setSource(bytes, XContentType.JSON).get());
|
||||
|
||||
assertThat(emptyFieldNameException.getMessage(), containsString(
|
||||
"object field cannot contain only whitespace: ['top.aoeu. ']"));
|
||||
}
|
||||
|
||||
public void testBlankFieldNames() throws Exception {
|
||||
final BytesReference bytes = XContentFactory.jsonBuilder()
|
||||
.startObject()
|
||||
|
|
Loading…
Reference in New Issue