mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-23 13:26:02 +00:00
SQL: Fix NPE for parameterized LIKE/RLIKE (#53573)
Fix NPE when `null` is passed as a parameter for a parameterized pattern of LIKE/RLIKE. e.g.: `field LIKE ?` params=[null]` Check for null pattern in LIKE/RLIKE as for RLIKE (RegexpQuery) we get an IllegalArgumentExpression from Lucence but for LIKE (WildcardQuery) we get an NPE. Fixes: #53557 (cherry picked from commit ec3481ed13254ecdec32acf7a0fafd536ec77aff)
This commit is contained in:
parent
94da4ca3fc
commit
723034001c
@ -264,6 +264,9 @@ abstract class ExpressionBuilder extends IdentifierBuilder {
|
||||
}
|
||||
|
||||
String pattern = string(ctx.value);
|
||||
if (pattern == null) {
|
||||
throw new ParsingException(source(ctx.value), "Pattern must not be [null]");
|
||||
}
|
||||
int pos = pattern.indexOf('*');
|
||||
if (pos >= 0) {
|
||||
throw new ParsingException(source(ctx.value),
|
||||
|
@ -21,16 +21,19 @@ import org.elasticsearch.xpack.sql.expression.predicate.conditional.IfConditiona
|
||||
import org.elasticsearch.xpack.sql.expression.predicate.operator.arithmetic.Add;
|
||||
import org.elasticsearch.xpack.sql.expression.predicate.operator.arithmetic.Mul;
|
||||
import org.elasticsearch.xpack.sql.expression.predicate.operator.arithmetic.Sub;
|
||||
import org.elasticsearch.xpack.sql.proto.SqlTypedParamValue;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.time.Period;
|
||||
import java.time.temporal.TemporalAmount;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
|
||||
import static java.lang.String.format;
|
||||
import static org.elasticsearch.xpack.ql.type.DataTypes.BOOLEAN;
|
||||
import static org.elasticsearch.xpack.ql.type.DataTypes.DOUBLE;
|
||||
import static org.elasticsearch.xpack.ql.type.DataTypes.INTEGER;
|
||||
import static org.elasticsearch.xpack.ql.type.DataTypes.KEYWORD;
|
||||
import static org.elasticsearch.xpack.ql.type.DataTypes.LONG;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
|
||||
@ -542,4 +545,11 @@ public class ExpressionTests extends ESTestCase {
|
||||
assertEquals("WHEN 1 THEN 'one'", ifc.sourceText());
|
||||
assertEquals("many", c.elseResult().toString());
|
||||
}
|
||||
|
||||
public void testLikePatternWithNullParameterNotAllowed() {
|
||||
ParsingException e = expectThrows(ParsingException.class,
|
||||
() -> parser.createExpression("a LIKE ?",
|
||||
Collections.singletonList(new SqlTypedParamValue(KEYWORD.typeName(), null))));
|
||||
assertEquals("line 1:9: Pattern must not be [null]", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user