Skip to content

Commit 10454cf

Browse files
committed
Fix test issue
1 parent d32747a commit 10454cf

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

server/src/main/java/org/elasticsearch/ingest/IngestDocument.java

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,26 +1349,39 @@ private static String[] processPathParts(String fullPath, String[] pathParts, In
13491349
throw new IllegalArgumentException("path [" + fullPath + "] is not valid");
13501350
}
13511351
return switch (accessPattern) {
1352-
case CLASSIC -> pathParts;
1352+
case CLASSIC -> validateClassicFields(fullPath, pathParts);
13531353
case FLEXIBLE -> parseFlexibleFields(fullPath, pathParts);
13541354
};
13551355
}
13561356

1357+
/**
1358+
* Parses path syntax that is specific to the {@link IngestPipelineFieldAccessPattern#CLASSIC} ingest doc access pattern. Supports
1359+
* syntax like context aware array access.
1360+
* @param fullPath The un-split path to use for error messages
1361+
* @param pathParts The tokenized field path to parse
1362+
* @return An array of Strings
1363+
*/
1364+
private static String[] validateClassicFields(String fullPath, String[] pathParts) {
1365+
for (String pathPart : pathParts) {
1366+
if (pathPart.isEmpty()) {
1367+
throw new IllegalArgumentException("path [" + fullPath + "] is not valid");
1368+
}
1369+
}
1370+
return pathParts;
1371+
}
1372+
13571373
/**
13581374
* Parses path syntax that is specific to the {@link IngestPipelineFieldAccessPattern#FLEXIBLE} ingest doc access pattern. Supports
13591375
* syntax like square bracket array access, which is the only way to index arrays in flexible mode.
13601376
* @param fullPath The un-split path to use for error messages
13611377
* @param pathParts The tokenized field path to parse
1362-
* @return An array of Elements
1378+
* @return An array of Strings
13631379
*/
13641380
private static String[] parseFlexibleFields(String fullPath, String[] pathParts) {
1365-
boolean invalidPath = Arrays.stream(pathParts).anyMatch(pathPart -> {
1366-
int openBracket = pathPart.indexOf('[');
1367-
int closedBracket = pathPart.indexOf(']');
1368-
return openBracket != -1 && closedBracket != -1;
1369-
});
1370-
if (invalidPath) {
1371-
throw new IllegalArgumentException("path [" + fullPath + "] is not valid");
1381+
for (String pathPart : pathParts) {
1382+
if (pathPart.isEmpty() || pathPart.indexOf('[') >= 0 || pathPart.indexOf(']') >= 0) {
1383+
throw new IllegalArgumentException("path [" + fullPath + "] is not valid");
1384+
}
13721385
}
13731386
return pathParts;
13741387
}

server/src/test/java/org/elasticsearch/ingest/IngestDocumentTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,8 @@ public void testPathParsingLogic() throws Exception {
216216
assertPathValid(doc, "a..");
217217
assertPathValid(doc, "a...");
218218
// Empty field names are not allowed in the beginning or middle of the path though
219-
assertPathInvalid(doc, ".a.b", "fieldName cannot be empty");
220-
assertPathInvalid(doc, "a..b", "fieldName cannot be empty");
219+
assertPathInvalid(doc, ".a.b", "path [.a.b] is not valid");
220+
assertPathInvalid(doc, "a..b", "path [a..b] is not valid");
221221
});
222222

223223
doWithAccessPattern(CLASSIC, (doc) -> {

0 commit comments

Comments
 (0)