File tree 2 files changed +22
-0
lines changed
main/java/org/elasticsearch/index/mapper
test/java/org/elasticsearch/index/mapper 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -180,6 +180,11 @@ private static String[] splitAndValidatePath(String fullFieldPath) {
180
180
String [] parts = fullFieldPath .split ("\\ ." );
181
181
for (String part : parts ) {
182
182
if (Strings .hasText (part ) == false ) {
183
+ // check if the field name contains only whitespace
184
+ if (Strings .isEmpty (part ) == false ) {
185
+ throw new IllegalArgumentException (
186
+ "object field cannot contain only whitespace: ['" + fullFieldPath + "']" );
187
+ }
183
188
throw new IllegalArgumentException (
184
189
"object field starting or ending with a [.] makes object resolution ambiguous: [" + fullFieldPath + "]" );
185
190
}
Original file line number Diff line number Diff line change @@ -1377,6 +1377,23 @@ public void testDynamicFieldsStartingAndEndingWithDot() throws Exception {
1377
1377
}
1378
1378
}
1379
1379
1380
+ public void testDynamicFieldsEmptyName () throws Exception {
1381
+ BytesReference bytes = XContentFactory .jsonBuilder ()
1382
+ .startObject ().startArray ("top." )
1383
+ .startObject ()
1384
+ .startObject ("aoeu" )
1385
+ .field ("a" , 1 ).field (" " , 2 )
1386
+ .endObject ()
1387
+ .endObject ().endArray ()
1388
+ .endObject ().bytes ();
1389
+
1390
+ IllegalArgumentException emptyFieldNameException = expectThrows (IllegalArgumentException .class ,
1391
+ () -> client ().prepareIndex ("idx" , "type" ).setSource (bytes , XContentType .JSON ).get ());
1392
+
1393
+ assertThat (emptyFieldNameException .getMessage (), containsString (
1394
+ "object field cannot contain only whitespace: ['top.aoeu. ']" ));
1395
+ }
1396
+
1380
1397
public void testBlankFieldNames () throws Exception {
1381
1398
final BytesReference bytes = XContentFactory .jsonBuilder ()
1382
1399
.startObject ()
You can’t perform that action at this time.
0 commit comments