Apache Solr open-source search software
SOLR-13203: return 400 on invalid dynamic field for edismax uf (#1502)
mrsoong291e358a3d78
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex d03c1a2c8c9..9a748545a16 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -221,6 +221,8 @@ Bug Fixes* SOLR-14467: Fix relatedness() stat in json.facets to no longer cause server errors (or nonsense results)when combined with allBuckets:true. (Michael Gibney, hossman)+* SOLR-13203: Return 400 status code on invalid dynamic field for Edismax's user Fields+ (Johannes Kloos, mrsoong via Munendra S N)Other Changes---------------------diff --git a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.javaindex 9c8672c7aa2..fce9416ad59 100644--- a/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java+++ b/solr/core/src/java/org/apache/solr/search/ExtendedDismaxQParser.java@@ -51,6 +51,7 @@ import org.apache.lucene.search.Query;import org.apache.lucene.search.spans.SpanQuery;import org.apache.solr.analysis.TokenizerChain;import org.apache.solr.common.SolrException;+import org.apache.solr.common.SolrException.ErrorCode;import org.apache.solr.common.params.DisMaxParams;import org.apache.solr.common.params.SolrParams;import org.apache.solr.common.util.NamedList;@@ -1609,7 +1610,7 @@ public class ExtendedDismaxQParser extends QParser {str=wildcard.substring(0,wildcard.length()-1);}else {- throw new RuntimeException("dynamic field name must start or end with *");+ throw new SolrException(ErrorCode.BAD_REQUEST, "dynamic field name must start or end with *");}}diff --git a/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java b/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.javaindex e16df5e92b6..9945dfa6dd4 100644--- a/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java+++ b/solr/core/src/test/org/apache/solr/search/TestExtendedDismaxParser.java@@ -709,6 +709,24 @@ public class TestExtendedDismaxParser extends SolrTestCaseJ4 {assertQ(req("defType","edismax", "q","Zapp Pig", "qf","myalias^100 name", "f.myalias.qf","trait_ss^0.1"), "//result/doc[1]/str[@name='id']=47", "//result/doc[2]/str[@name='id']=42");//Now the order should be inverse}+ /** SOLR-13203 **/+ public void testUfDynamicField() throws Exception {+ try {+ ignoreException("dynamic field");++ SolrException exception = expectThrows(SolrException.class,+ () -> h.query(req("uf", "fl=trait*,id", "defType", "edismax")));+ assertEquals(SolrException.ErrorCode.BAD_REQUEST.code, exception.code());+ assertEquals("dynamic field name must start or end with *",+ exception.getMessage());+ } finally {+ resetExceptionIgnores();+ }++ // simple test to validate dynamic uf parsing works+ assertQ(req("uf", "trait* id", "defType", "edismax"));+ }+public void testCyclicAliasing() throws Exception {try {ignoreException(".*Field aliases lead to a cycle.*");