From 291e358a3d7823082316bd0fa63642b9900adf27 Mon Sep 17 00:00:00 2001 From: mrsoong Date: Sun, 7 Jun 2020 08:12:25 -0400 Subject: [PATCH] SOLR-13203: return 400 on invalid dynamic field for edismax uf (#1502) --- solr/CHANGES.txt | 2 ++ .../solr/search/ExtendedDismaxQParser.java | 3 ++- .../solr/search/TestExtendedDismaxParser.java | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index 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.java index 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.java index 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.*");