Skip to content

Commit

Permalink
correct XML sanitization of some characters in messages which made xml
Browse files Browse the repository at this point in the history
invalid so nothing showed
  • Loading branch information
velias committed Aug 16, 2018
1 parent d13c104 commit 278ea22
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Plugin .jar file is then placed in /target subfolder
Changelog
-------------

1.5 - 2018-08-16
- correct XML sanitization of some characters in messages which made xml invalid so nothing showed

1.4 - 2016-10-06
- update to work in jira 7.x (not compatible with older jira versions anymore)
- added progress indicator shown during data loading
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.jboss.labs.jira.plugin</groupId>
<artifactId>livelogviewer</artifactId>
<version>1.4</version>
<version>1.5</version>

<name>Live Log Viewer</name>
<packaging>atlassian-plugin</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws Se
resp.setContentType("application/xml");
resp.setHeader("Cache-Control", "no-cache, must-revalidate");
resp.setHeader("Expires", "Mon, 28 May 2012 01:00:00 GMT");
resp.setCharacterEncoding("UTF-8");
PrintWriter writer = resp.getWriter();
writer.write("<?xml version='1.0' encoding='UTF-8'?>\n");
writer.write("<events>");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jboss.labs.jira.plugin.livelogviewer;

import java.util.regex.Pattern;

import org.apache.log4j.Layout;
import org.apache.log4j.helpers.Transform;
import org.apache.log4j.spi.LoggingEvent;
Expand All @@ -22,7 +24,7 @@ public String format(LoggingEvent event) {
sb.append(" thread=\"").append(event.getThreadName()).append("\"");
sb.append(">");
sb.append("<message><![CDATA[");
Transform.appendEscapingCDATA(sb, event.getRenderedMessage());
Transform.appendEscapingCDATA(sb, sanitizeXmlChars(event.getRenderedMessage()));
sb.append("]]>");
sb.append("</message>");
if (event.getThrowableInformation() != null) {
Expand All @@ -40,6 +42,18 @@ public String format(LoggingEvent event) {
return sb.toString();
}

public static String sanitizeXmlChars(String xml) {
if (xml == null || ("".equals(xml))) return "";
// ref : http://www.w3.org/TR/REC-xml/#charsets
// jdk 7
Pattern xmlInvalidChars =
Pattern.compile(
"[^\\u0009\\u000A\\u000D\\u0020-\\uD7FF\\uE000-\\uFFFD\\x{10000}-\\x{10FFFF}]"

);
return xmlInvalidChars.matcher(xml).replaceAll(".");
}

@Override
public boolean ignoresThrowable() {
return false;
Expand Down

0 comments on commit 278ea22

Please sign in to comment.