Skip to content

Commit 49396ec

Browse files
Fix missing sort in Strings#INVALID_FILENAME_CHARS and assert invalid
chars in error string
1 parent b462da0 commit 49396ec

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

server/src/main/java/org/elasticsearch/common/Strings.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ private static String changeFirstCharacterCase(String str, boolean capitalize) {
282282
static final Set<Character> INVALID_CHARS = Set.of('\\', '/', '*', '?', '"', '<', '>', '|', ' ', ',');
283283

284284
public static final String INVALID_FILENAME_CHARS = INVALID_CHARS.stream()
285+
.sorted()
285286
.map(c -> "'" + c + "'")
286287
.collect(Collectors.joining(",", "[", "]"));
287288

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ abstract class IdentifierBuilder extends AbstractBuilder {
3434

3535
private static final String BLANK_INDEX_ERROR_MESSAGE = "Blank index specified in index pattern";
3636

37+
private static final String INVALID_ESQL_CHARS = Strings.INVALID_FILENAME_CHARS.replace("'*',", "");
38+
3739
@Override
3840
public String visitIdentifier(IdentifierContext ctx) {
3941
return ctx == null ? null : unquoteIdentifier(ctx.QUOTED_IDENTIFIER(), ctx.UNQUOTED_IDENTIFIER());
@@ -311,8 +313,7 @@ private static void resolveAndValidateIndex(String index, EsqlBaseParser.IndexPa
311313
* mislead the user by mentioning this char in the error message.
312314
*/
313315
if (e.getMessage().contains("must not contain the following characters")) {
314-
var updatedInvalidChars = Strings.INVALID_FILENAME_CHARS.replace("'*',", "");
315-
throwInvalidIndexNameException(index, "must not contain the following characters " + updatedInvalidChars, ctx);
316+
throwInvalidIndexNameException(index, "must not contain the following characters " + INVALID_ESQL_CHARS, ctx);
316317
}
317318

318319
throw new ParsingException(e, source(ctx), e.getMessage());

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3286,7 +3286,12 @@ public void testInvalidPatternsWithIntermittentQuotes() {
32863286
var invalidIndexName = "foo" + randomInvalidChar + "bar";
32873287
var remoteIndexWithInvalidChar = quote(randomIdentifier() + ":" + invalidIndexName);
32883288
var query = "FROM " + randomIndex + "," + remoteIndexWithInvalidChar;
3289-
expectError(query, "Invalid index name [" + invalidIndexName + "], must not contain the following characters");
3289+
expectError(
3290+
query,
3291+
"Invalid index name ["
3292+
+ invalidIndexName
3293+
+ "], must not contain the following characters [' ','\"',',','/','<','>','?','\\','|']"
3294+
);
32903295
}
32913296

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

0 commit comments

Comments
 (0)