Changeset 13054


Ignore:
Timestamp:
2006-10-09T13:20:00+13:00 (18 years ago)
Author:
mdewsnip
Message:

Now puts the terms through xmlSafe() as well, to prevent invalid XML with weird terms containing punctuation.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/src/java/org/nzdl/gsdl/LuceneWrap/GS2LuceneQuery.java

    r12999 r13054  
    225225        // something like this:
    226226        // if (term.field().equals(TEXTFIELD))
    227         query_results_xml.append("  <Term value=\"" + term.text() + "\" field=\"" + term.field() + "\" freq=\"" + term_freq + "\" />\n");
     227        query_results_xml.append("  <Term value=\"" + xmlSafe(term.text()) + "\" field=\"" + term.field() + "\" freq=\"" + term_freq + "\" />\n");
    228228        }
    229229
     
    307307
    308308    private static String xmlSafe(String text) {
    309         return text.replaceAll("\\&", "\\&amp;");
    310     }
     309    text = text.replaceAll("&","&amp;amp;");
     310    text = text.replaceAll("<","&amp;lt;");
     311    text = text.replaceAll(">","&amp;gt;");
     312    text = text.replaceAll("'","&amp;#039;");
     313    text = text.replaceAll("\\\"","&amp;quot;");
     314    return text;
     315    }
     316
    311317
    312318    private static Query parseQuery(IndexReader reader, QueryParser query_parser, String query_string, String fuzziness)
  • trunk/indexers/lucene-gs/src/org/greenstone/LuceneWrapper/GS2LuceneQuery.java

    r12999 r13054  
    225225        // something like this:
    226226        // if (term.field().equals(TEXTFIELD))
    227         query_results_xml.append("  <Term value=\"" + term.text() + "\" field=\"" + term.field() + "\" freq=\"" + term_freq + "\" />\n");
     227        query_results_xml.append("  <Term value=\"" + xmlSafe(term.text()) + "\" field=\"" + term.field() + "\" freq=\"" + term_freq + "\" />\n");
    228228        }
    229229
     
    307307
    308308    private static String xmlSafe(String text) {
    309         return text.replaceAll("\\&", "\\&amp;");
    310     }
     309    text = text.replaceAll("&","&amp;amp;");
     310    text = text.replaceAll("<","&amp;lt;");
     311    text = text.replaceAll(">","&amp;gt;");
     312    text = text.replaceAll("'","&amp;#039;");
     313    text = text.replaceAll("\\\"","&amp;quot;");
     314    return text;
     315    }
     316
    311317
    312318    private static Query parseQuery(IndexReader reader, QueryParser query_parser, String query_string, String fuzziness)
Note: See TracChangeset for help on using the changeset viewer.