You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@solr.apache.org by ep...@apache.org on 2024/03/01 16:02:12 UTC
(solr) branch branch_9x updated: SOLR-17186: Streaming query breaks if token contains backtick (#2321)
This is an automated email from the ASF dual-hosted git repository.
epugh pushed a commit to branch branch_9x
in repository https://gitbox.apache.org/repos/asf/solr.git
The following commit(s) were added to refs/heads/branch_9x by this push:
new 74e9b3a5a41 SOLR-17186: Streaming query breaks if token contains backtick (#2321)
74e9b3a5a41 is described below
commit 74e9b3a5a41254597c081b1f92ff8c1178d75edc
Author: Rahul Goswami <ra...@gmail.com>
AuthorDate: Fri Mar 1 11:00:39 2024 -0500
SOLR-17186: Streaming query breaks if token contains backtick (#2321)
---------
Co-authored-by: Eric Pugh <ep...@opensourceconnections.com>
---
solr/CHANGES.txt | 4 +++-
.../io/stream/expr/StreamExpressionParser.java | 8 +++----
.../solrj/io/stream/StreamExpressionTest.java | 27 ++++++++++++++++++++++
3 files changed, 34 insertions(+), 5 deletions(-)
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 71be998126c..441512e1f63 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -26,7 +26,7 @@ Improvements
* SOLR-17145: The INSTALLSHARDDATA API now includes a 'requestid' field when run asynchronously (Jason Gerlowski)
-* SOLR-17159: bin/solr post now has proper unit testing. Users can specify a --dry-run option to
+* SOLR-17159: bin/solr post now has proper unit testing. Users can specify a --dry-run option to
simulate posting documents without sending them to Solr. (Eric Pugh)
* SOLR-17058: Add 'distrib.statsCache' parameter to disable distributed stats requests at query time. (Wei Wang, Mikhail Khludnev)
@@ -49,6 +49,8 @@ Bug Fixes
* SOLR-17148: Fixing Config API overlay property enabling or disabling the cache (Sanjay Dutt, hossman, Eric Pugh)
+* SOLR-17186: Streaming query breaks if token contains backtick (Rahul Goswami via Eric Pugh)
+
Dependency Upgrades
---------------------
(No changes)
diff --git a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamExpressionParser.java b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamExpressionParser.java
index a5b7c5f783e..7d9a1fe09a7 100644
--- a/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamExpressionParser.java
+++ b/solr/solrj-streaming/src/java/org/apache/solr/client/solrj/io/stream/expr/StreamExpressionParser.java
@@ -132,17 +132,17 @@ public class StreamExpressionParser {
}
}
- // If contains ` replace with "
+ // If contains ` replace with ", except when ` is escaped in the query as (\`)
// This allows ` to be used as a quote character
-
if (parameter.contains("`")) {
- parameter = parameter.replace('`', '"');
+ // Below replacement regex does a negative lookbehind and replaces ` with " only when NOT
+ // preceded by \
+ parameter = parameter.replaceAll("(?<!\\\\)`", "\"");
if (0 == parameter.length()) {
throw new IllegalArgumentException(
String.format(Locale.ROOT, "'%s' is not a proper named parameter clause", working));
}
}
-
namedParameter.setParameter(new StreamExpressionValue(parameter));
}
diff --git a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
index 34d3201a001..22ce4a5eac3 100644
--- a/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
+++ b/solr/solrj-streaming/src/test/org/apache/solr/client/solrj/io/stream/StreamExpressionTest.java
@@ -3638,6 +3638,33 @@ public class StreamExpressionTest extends SolrCloudTestCase {
Tuple tuple = tuples.get(0);
assertEquals("hello", tuple.get("id"));
assertEquals("l b c d c e", tuple.get("test_t"));
+
+ // Below is the case when the search token itself contains a ` and is escaped
+ UpdateRequest updateRequest2 = new UpdateRequest();
+ updateRequest2.add(id, "hello2", "test_t", "l b c d color`s e");
+ updateRequest2.add(id, "hello3", "test_t", "b c d colors e");
+ updateRequest2.commit(cluster.getSolrClient(), COLLECTIONORALIAS);
+
+ String expr2 =
+ "search("
+ + COLLECTIONORALIAS
+ + ", q=\"`c d color\\`s e`\", fl=\"id,test_t\", sort=\"id desc\")";
+
+ ModifiableSolrParams paramsLoc2 = new ModifiableSolrParams();
+ paramsLoc2.set("expr", expr2);
+ paramsLoc2.set("qt", "/stream");
+
+ String url2 =
+ cluster.getJettySolrRunners().get(0).getBaseUrl().toString() + "/" + COLLECTIONORALIAS;
+ TupleStream solrStream2 = new SolrStream(url2, paramsLoc2);
+
+ StreamContext context2 = new StreamContext();
+ solrStream2.setStreamContext(context2);
+ List<Tuple> tuples2 = getTuples(solrStream2);
+ assertEquals(1, tuples2.size());
+ Tuple tuple2 = tuples2.get(0);
+ assertEquals("hello2", tuple2.get("id"));
+ assertEquals("l b c d color`s e", tuple2.get("test_t"));
}
private Map<String, Double> getIdToLabel(TupleStream stream, String outField) throws IOException {