Apache Lucene open-source search software
SOLR-12190: properly escape output in GraphMLResponseWriter
yonik8d20fc575bab
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex c07c1f7df8b..360d6639799 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -139,6 +139,9 @@ Bug Fixes* SOLR-12201: TestReplicationHandler.doTestIndexFetchOnMasterRestart(): handle unexpected replication failures(Steve Rowe)++* SOLR-12190: Need to properly escape output in GraphMLResponseWriter. (yonik)+Optimizations----------------------diff --git a/solr/core/src/java/org/apache/solr/response/GraphMLResponseWriter.java b/solr/core/src/java/org/apache/solr/response/GraphMLResponseWriter.javaindex 7f2fac22b73..c41e2a2ca62 100644--- a/solr/core/src/java/org/apache/solr/response/GraphMLResponseWriter.java+++ b/solr/core/src/java/org/apache/solr/response/GraphMLResponseWriter.java@@ -97,7 +97,7 @@ public class GraphMLResponseWriter implements QueryResponseWriter {id = tuple.getString("collection") + "." + id;}- writer.write("<node id=\""+replace(id)+"\"");+ printWriter.write("<node id=\""+ xmlEscape(id)+"\"");List<String> outfields = new ArrayList();Iterator<String> keys = tuple.fields.keySet().iterator();@@ -115,7 +115,7 @@ public class GraphMLResponseWriter implements QueryResponseWriter {for (String nodeAttribute : outfields) {Object o = tuple.get(nodeAttribute);if (o != null) {- printWriter.println("<data key=\""+nodeAttribute+"\">" + o.toString() + "</data>");+ printWriter.println("<data key=\"" + xmlEscape(nodeAttribute) + "\">" + xmlEscape(o.toString()) + "</data>");}}printWriter.println("</node>");@@ -128,20 +128,20 @@ public class GraphMLResponseWriter implements QueryResponseWriter {if(ancestors != null) {for (String ancestor : ancestors) {++edgeCount;- writer.write("<edge id=\"" + edgeCount + "\" ");- writer.write(" source=\"" + replace(ancestor) + "\" ");- printWriter.println(" target=\"" + replace(id) + "\"/>");+ printWriter.write("<edge id=\"" + edgeCount + "\" ");+ printWriter.write(" source=\"" + xmlEscape(ancestor) + "\" ");+ printWriter.println(" target=\"" + xmlEscape(id) + "\"/>");}}}- writer.write("</graph></graphml>");+ printWriter.write("</graph></graphml>");} finally {stream.close();}}- private String replace(String s) {+ private String xmlEscape(String s) {if(s.indexOf(">") > -1) {s = s.replace(">", ">");}