diff --git a/src/main/java/htmlpublisher/HtmlPublisher.java b/src/main/java/htmlpublisher/HtmlPublisher.java index dc86d9e..09e507b 100644 --- a/src/main/java/htmlpublisher/HtmlPublisher.java +++ b/src/main/java/htmlpublisher/HtmlPublisher.java @@ -81,6 +81,8 @@ import edu.umd.cs.findbugs.annotations.NonNull; +import static hudson.Functions.htmlAttributeEscape; + /** * Saves HTML reports for the project and publishes them. @@ -130,7 +132,7 @@ private static String writeFile(List lines, File path) throws IOExceptio return Util.toHexString(sha1.digest()); } - public List readFile(String filePath) throws + public List readFile(String filePath) throws java.io.IOException { return readFile(filePath, this.getClass()); } @@ -302,7 +304,7 @@ public static boolean publishReports(Run build, FilePath workspace, TaskLi // On windows file paths contains back slashes, but // in the HTML file we do not want them, so replace them with forward slash report = report.replace("\\", "/"); - + // Ignore blank report names caused by trailing or double commas. if (report.isEmpty()) { continue; @@ -318,13 +320,13 @@ public static boolean publishReports(Run build, FilePath workspace, TaskLi } else { reportFile = report; } - String tabItem = "
  • " + getTitle(reportFile, titles, j) + "
  • "; + String tabItem = "
  • " + htmlAttributeEscape(getTitle(reportFile, titles, j)) + "
  • "; reportLines.add(tabItem); } // Add the JS to change the link as appropriate. String hudsonUrl = Jenkins.get().getRootUrl(); Job job = build.getParent(); - reportLines.add(""); + reportLines.add(""); // If the URL isn't configured in Hudson, the best we can do is attempt to go Back. if (hudsonUrl == null) { reportLines.add(""); diff --git a/src/main/resources/htmlpublisher/HtmlPublisherTarget/BaseHTMLAction/index.groovy b/src/main/resources/htmlpublisher/HtmlPublisherTarget/BaseHTMLAction/index.groovy index 51e94b3..ab0b282 100644 --- a/src/main/resources/htmlpublisher/HtmlPublisherTarget/BaseHTMLAction/index.groovy +++ b/src/main/resources/htmlpublisher/HtmlPublisherTarget/BaseHTMLAction/index.groovy @@ -3,6 +3,7 @@ package htmlpublisher.HtmlPublisherTarget.BaseHTMLAction import htmlpublisher.HtmlPublisher import htmlpublisher.HtmlPublisherTarget import hudson.Util +import hudson.model.Descriptor import java.security.MessageDigest @@ -57,6 +58,30 @@ def serveWrapperLegacyDirectly() { def legacyFile = new File(my.dir(), "htmlpublisher-wrapper.html") + def scriptPattern = legacyFile.text =~ /( + + + + + +

    +

    Zip

    + +
      + + + +
    +
    + +
    + + + diff --git a/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/builds/1/htmlreports/HTML_20Report/test.txt b/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/builds/1/htmlreports/HTML_20Report/test.txt new file mode 100644 index 0000000..345e6ae --- /dev/null +++ b/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/builds/1/htmlreports/HTML_20Report/test.txt @@ -0,0 +1 @@ +Test diff --git a/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/builds/1/log b/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/builds/1/log new file mode 100644 index 0000000..09a9085 --- /dev/null +++ b/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/builds/1/log @@ -0,0 +1,8 @@ +Started by user unknown or anonymous +Running as SYSTEM +Building in workspace workspace/"+alert(1)+" +["+alert(1)+"] $ /bin/sh -xe /tmp/jenkins2940273657363065808.sh ++ echo Test +[htmlpublisher] Archiving HTML reports... +[htmlpublisher] Archiving at BUILD level workspace/"+alert(1)+" to jobs/"+alert(1)+"/builds/1/htmlreports/HTML_20Report +Finished: SUCCESS diff --git a/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/builds/legacyIds b/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/builds/legacyIds new file mode 100644 index 0000000..e69de29 diff --git a/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/builds/permalinks b/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/builds/permalinks new file mode 100644 index 0000000..8c155db --- /dev/null +++ b/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/builds/permalinks @@ -0,0 +1,6 @@ +lastCompletedBuild 1 +lastFailedBuild -1 +lastStableBuild 1 +lastSuccessfulBuild 1 +lastUnstableBuild -1 +lastUnsuccessfulBuild -1 diff --git a/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/config.xml b/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/config.xml new file mode 100644 index 0000000..c451e27 --- /dev/null +++ b/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/config.xml @@ -0,0 +1,38 @@ + + + + false + + + true + false + false + false + + false + + + echo "Test" > test.txt + + + + + + + + HTML Report + + index.html + false + + true + false + **/* + true + true + + + + + + \ No newline at end of file diff --git a/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/nextBuildNumber b/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/nextBuildNumber new file mode 100644 index 0000000..0cfbf08 --- /dev/null +++ b/src/test/resources/htmlpublisher/Security3302Test/oldReportJobNameTest/jobs/testJob/nextBuildNumber @@ -0,0 +1 @@ +2