Skip to content

Apache Lucene open-source search software

tests: let json parser handle single quoted strings

Yonik Seeley0ff3ea426fdd
diff --git a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
index 8ce2f2791d3..078b75d59ab 100644
--- a/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
+++ b/solr/test-framework/src/java/org/apache/solr/SolrTestCaseJ4.java
@@ -750,7 +750,7 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
try {
String m = (null == message) ? "" : message + " ";
String response = h.query(req);
-
+
if (req.getParams().getBool("facet", false)) {
// add a test to ensure that faceting did not throw an exception
// internally, where it would be added to facet_counts/exception
@@ -814,9 +814,9 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
}
/**
* Validates a query matches some JSON test expressions and closes the
- * query. The text expression is of the form path:JSON. To facilitate
- * easy embedding in Java strings, the JSON tests can have double quotes
- * replaced with single quotes.
+ * query. The text expression is of the form path:JSON. The Noggit JSON
+ * parser used accepts single quoted strings and bare strings to allow
+ * easy embedding in Java Strings.
* <p>
* Please use this with care: this makes it easy to match complete
* structures, but doing so can result in fragile tests if you are
@@ -1129,22 +1129,15 @@ public abstract class SolrTestCaseJ4 extends LuceneTestCase {
return Arrays.asList(docs);
}
- /** Converts "test JSON" and returns standard JSON.
- * Currently this only consists of changing unescaped single quotes to double quotes,
- * and escaped single quotes to single quotes.
- *
- * The primary purpose is to be able to easily embed JSON strings in a JAVA string
- * with the best readability.
+ /** Converts "test JSON" strings into JSON parseable by our JSON parser.
+ * For example, this method changed single quoted strings into double quoted strings before
+ * the parser could natively handle them.
*
* This transformation is automatically applied to JSON test srings (like assertJQ).
*/
public static String json(String testJSON) {
- testJSON = nonEscapedSingleQuotePattern.matcher(testJSON).replaceAll("\"");
- testJSON = escapedSingleQuotePattern.matcher(testJSON).replaceAll("'");
return testJSON;
}
- private static Pattern nonEscapedSingleQuotePattern = Pattern.compile("(?<!\\\\)\'");
- private static Pattern escapedSingleQuotePattern = Pattern.compile("\\\\\'");
/** Creates JSON from a SolrInputDocument. Doesn't currently handle boosts.