Skip to content

Apache Lucene open-source search software

don't generate invalid random regexps: the toString method of RegExp doesnt escape

Robert Muir2b988eafaa52
diff --git a/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java b/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java
index a2ac623618f..7ddca91d521 100644
--- a/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java
+++ b/lucene/src/test/org/apache/lucene/search/TestRegexpRandom2.java
@@ -86,9 +86,9 @@ public class TestRegexpRandom2 extends LuceneTestCase {
private class DumbRegexpQuery extends MultiTermQuery {
private final Automaton automaton;
- DumbRegexpQuery(Term term) {
+ DumbRegexpQuery(Term term, int flags) {
super(term.field());
- RegExp re = new RegExp(term.text());
+ RegExp re = new RegExp(term.text(), flags);
automaton = re.toAutomaton();
}
@@ -130,8 +130,8 @@ public class TestRegexpRandom2 extends LuceneTestCase {
* simple regexpquery implementation.
*/
private void assertSame(String regexp) throws IOException {
- RegexpQuery smart = new RegexpQuery(new Term("field", regexp));
- DumbRegexpQuery dumb = new DumbRegexpQuery(new Term("field", regexp));
+ RegexpQuery smart = new RegexpQuery(new Term("field", regexp), RegExp.NONE);
+ DumbRegexpQuery dumb = new DumbRegexpQuery(new Term("field", regexp), RegExp.NONE);
// we can't compare the two if automaton rewrites to a simpler enum.
// for example: "a\uda07\udcc7?.*?" gets rewritten to a simpler query:
diff --git a/lucene/src/test/org/apache/lucene/util/automaton/AutomatonTestUtil.java b/lucene/src/test/org/apache/lucene/util/automaton/AutomatonTestUtil.java
index 013ea0e8b64..a1dd2da5072 100644
--- a/lucene/src/test/org/apache/lucene/util/automaton/AutomatonTestUtil.java
+++ b/lucene/src/test/org/apache/lucene/util/automaton/AutomatonTestUtil.java
@@ -40,7 +40,9 @@ public class AutomatonTestUtil {
if (!UnicodeUtil.validUTF16String(regexp))
continue;
try {
- return new RegExp(regexp, RegExp.NONE);
+ // NOTE: we parse-tostring-parse again, because we are
+ // really abusing RegExp.toString() here (its just for debugging)
+ return new RegExp(new RegExp(regexp, RegExp.NONE).toString(), RegExp.NONE);
} catch (Exception e) {}
}
}