From ee2f7f827318fb67a405a0fe9cd09a6d6216e826 Mon Sep 17 00:00:00 2001 From: Aurelien FOUCRET Date: Fri, 25 Oct 2024 17:18:47 +0200 Subject: [PATCH] Apply suggestion from review. --- .../org/elasticsearch/xpack/kql/parser/ParserUtils.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/ParserUtils.java b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/ParserUtils.java index 2642d43c46390..134dc6296503d 100644 --- a/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/ParserUtils.java +++ b/x-pack/plugin/kql/src/main/java/org/elasticsearch/xpack/kql/parser/ParserUtils.java @@ -27,6 +27,7 @@ public final class ParserUtils { private static final String UNQUOTED_LITERAL_TERM_DELIMITER = " "; private static final char ESCAPE_CHAR = '\\'; private static final char QUOTE_CHAR = '"'; + private static final char WILDCARD_CHAR = '"'; private ParserUtils() { throw new UnsupportedOperationException("No need to instantiate this class"); @@ -102,11 +103,11 @@ public static String escapeLuceneQueryString(String queryText, boolean preserveW if (preserveWildcards) { StringBuilder escapedQuery = new StringBuilder(queryText.length()); StringBuilder subpart = new StringBuilder(queryText.length()); - for (int i = 0; i < queryText.length(); i++) { - char currentChar = queryText.charAt(i); - if (currentChar == '*') { + + for (char currentChar : queryText.toCharArray()) { + if (currentChar == WILDCARD_CHAR) { escapedQuery.append(QueryParser.escape(subpart.toString())).append(currentChar); - subpart = new StringBuilder(queryText.length() - i); + subpart.setLength(0); } else { subpart.append(currentChar); }