Skip to content

Commit 3776df5

Browse files
Refactor dropping asterisk from invalid chars
1 parent 7989610 commit 3776df5

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/parser/IdentifierBuilder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,17 +305,17 @@ private static void resolveAndValidateIndex(String index, EsqlBaseParser.IndexPa
305305
return;
306306
}
307307

308-
InvalidIndexNameException errorToThrow = e;
309308
/*
310309
* We only modify this particular message because it mentions '*' as an invalid char.
311310
* However, we do allow asterisk in the index patterns: wildcarded patterns. Let's not
312311
* mislead the user by mentioning this char in the error message.
313312
*/
314313
if (e.getMessage().contains("must not contain the following characters")) {
315-
errorToThrow = new InvalidIndexNameException(index, e.getMessage().replace("'*',", ""));
314+
var updatedInvalidChars = Strings.INVALID_FILENAME_CHARS.replace("'*',", "");
315+
throwInvalidIndexNameException(index, "must not contain the following characters " + updatedInvalidChars, ctx);
316316
}
317317

318-
throw new ParsingException(errorToThrow, source(ctx), errorToThrow.getMessage());
318+
throw new ParsingException(e, source(ctx), e.getMessage());
319319
}
320320
}
321321

x-pack/plugin/esql/src/test/java/org/elasticsearch/xpack/esql/parser/StatementParserTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3285,7 +3285,7 @@ public void testInvalidPatternsWithIntermittentQuotes() {
32853285
// Construct the new invalid index pattern.
32863286
var remoteIndexWithInvalidChar = quote(randomIdentifier() + ":" + "foo" + randomInvalidChar + "bar");
32873287
var query = "FROM " + randomIndex + "," + remoteIndexWithInvalidChar;
3288-
expectError(query, "must not contain the following characters ['\\',' ','\"','<','?','>','|',',','/']");
3288+
expectError(query, "must not contain the following characters ['\"',' ','\\','/',',','|','>','?','<']");
32893289
}
32903290

32913291
// Colon outside a quoted string should result in an ANTLR error: a comma is expected.

0 commit comments

Comments
 (0)