Uploaded image for project: 'Lucene - Core'
  1. Lucene - Core
  2. LUCENE-800

Incorrect parsing by QueryParser.parse() when it encounters backslashes (always eats one backslash.)

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.2
    • Component/s: core/queryparser
    • Labels:
      None
    • Lucene Fields:
      New

      Description

      Test code and output follow. Tested Lucene 1.9 version only. Affects hose who would index/search for Lucene's reserved characters.

      Description: When an input search string has a sequence of N (java-escaped) backslashes, where N >= 2, the QueryParser will produce a query in which that sequence has N-1 backslashes.

      TEST CODE:
      Analyzer analyzer = new WhitespaceAnalyzer();
      String[] queryStrs =

      {"item:\\\\", "item:\\\\*", "(item:\\\\ item:ABCD\\\\))", "(item:\\\\ item:ABCD\\\\)"}

      ;
      for (String queryStr : queryStrs) {
      System.out.println("--------------------------------------");
      System.out.println("String queryStr = " + queryStr);
      Query luceneQuery = null;
      try

      { luceneQuery = new QueryParser("_default_", analyzer).parse(queryStr); System.out.println("luceneQuery.toString() = " + luceneQuery.toString()); }

      catch (Exception e)

      { System.out.println(e.getClass().toString()); }

      }

      OUTPUT (with remarks in comment notation
      --------------------------------------
      String queryStr = item:
      luceneQuery.toString() = item:\ //One backslash has disappeared. Searcher will fail on this query.
      --------------------------------------
      String queryStr = item:
      *
      luceneQuery.toString() = item:* //One backslash has disappeared. This query will search for something unintended.
      --------------------------------------
      String queryStr = (item:
      item:ABCD
      ))
      luceneQuery.toString() = item:\ item:ABCD) //This should have thrown a ParseException because of an unescaped ')'. It did not.
      --------------------------------------
      String queryStr = (item:
      item:ABCD
      )
      class org.apache.lucene.queryParser.ParseException //...and this one should not have, but it did.

        Attachments

        1. Lucene-800.patch
          11 kB
          Michael Busch
        2. Lucene-800-more-tests.patch
          3 kB
          Doron Cohen

          Activity

            People

            • Assignee:
              michaelbusch Michael Busch
              Reporter:
              dnimkar Dilip Nimkar
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: