NIHVIVO-2425 Apply json-escaping to the query results to prevent JSON format errors

This commit is contained in:
ryounes 2011-03-28 15:57:11 +00:00
parent 1e16db9c0c
commit 445721f066
2 changed files with 8 additions and 5 deletions

View file

@ -29,6 +29,8 @@ import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TopDocs; import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.WildcardQuery; import org.apache.lucene.search.WildcardQuery;
import com.hp.hpl.jena.sparql.lib.org.json.JSONObject;
import edu.cornell.mannlib.vedit.beans.LoginStatusBean; import edu.cornell.mannlib.vedit.beans.LoginStatusBean;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest; import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController; import edu.cornell.mannlib.vitro.webapp.controller.ajax.VitroAjaxController;
@ -151,7 +153,7 @@ public class AutocompleteController extends VitroAjaxController {
private Analyzer getAnalyzer(ServletContext servletContext) throws SearchException { private Analyzer getAnalyzer(ServletContext servletContext) throws SearchException {
Object obj = servletContext.getAttribute(LuceneSetup.ANALYZER); Object obj = servletContext.getAttribute(LuceneSetup.ANALYZER);
if( obj == null || !(obj instanceof Analyzer) ) if( obj == null || !(obj instanceof Analyzer) )
throw new SearchException("Could not get anlyzer"); throw new SearchException("Could not get analyzer");
else else
return (Analyzer)obj; return (Analyzer)obj;
} }
@ -292,9 +294,9 @@ public class AutocompleteController extends VitroAjaxController {
private String label; private String label;
private String uri; private String uri;
SearchResult(String label, String value) { SearchResult(String label, String uri) {
this.label = label; this.label = JSONObject.quote(label);
this.uri = value; this.uri = JSONObject.quote(uri);
} }
public String getLabel() { public String getLabel() {

View file

@ -10,7 +10,8 @@
[ [
<#if results??> <#if results??>
<#list results as result> <#list results as result>
{ "label": "${result.label}", "uri": "${result.uri}" }<#if result_has_next>,</#if> <#-- result.label and result.uri are already quoted -->
{ "label": ${result.label}, "uri": ${result.uri} }<#if result_has_next>,</#if>
</#list> </#list>
</#if> </#if>
] ]