File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
main/java/org/elasticsearch/xpack/esql/action
test/java/org/elasticsearch/xpack/esql/action Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ pr : 134879
2+ summary : Throw 4xx instead of 5xx for ESQL malformed query params
3+ area : ES|QL
4+ type : bug
5+ issues :
6+ - 134618
Original file line number Diff line number Diff line change @@ -222,6 +222,18 @@ private static QueryParams parseParams(XContentParser p) throws IOException {
222222 }
223223 }
224224 }
225+ } else {
226+ errors .add (
227+ new XContentParseException (
228+ "Unexpected token ["
229+ + token
230+ + "] at "
231+ + p .getTokenLocation ()
232+ + ", expected "
233+ + XContentParser .Token .START_ARRAY
234+ + ". Please check documentation for the correct format of the 'params' field."
235+ )
236+ );
225237 }
226238 // don't allow mixed named and unnamed parameters
227239 if (namedParams .isEmpty () == false && unNamedParams .isEmpty () == false ) {
Original file line number Diff line number Diff line change @@ -408,6 +408,26 @@ public void testInvalidMultivaluedUnnamedParams() throws IOException {
408408 );
409409 }
410410
411+ public void testInvalidParamsString () {
412+ String query = randomAlphaOfLengthBetween (1 , 100 );
413+ String json1 = String .format (Locale .ROOT , """
414+ {
415+ "query": "%s",
416+ "params": {*}
417+ }""" , query );
418+ Exception e1 = expectThrows (XContentParseException .class , () -> parseEsqlQueryRequestSync (json1 ));
419+ String message1 = e1 .getCause ().getMessage ();
420+ assertThat ("Unexpected failure when parsing " + json1 + ". " + message1 , containsString ("Unexpected token [START_OBJECT]" ));
421+ String json2 = String .format (Locale .ROOT , """
422+ {
423+ "query": "%s",
424+ "params": "foo"
425+ }""" , query );
426+ Exception e2 = expectThrows (XContentParseException .class , () -> parseEsqlQueryRequestSync (json2 ));
427+ String message2 = e2 .getCause ().getMessage ();
428+ assertThat ("Unexpected failure when parsing " + json2 + ". " + message2 , containsString ("Unexpected token [VALUE_STRING]" ));
429+ }
430+
411431 public void testInvalidParamsForIdentifiersPatterns () throws IOException {
412432 String query = randomAlphaOfLengthBetween (1 , 100 );
413433 boolean columnar = randomBoolean ();
You can’t perform that action at this time.
0 commit comments