Skip to content

Commit 7c67b46

Browse files
author
Rob Petti
committed
[FIXED JENKINS-19548] use commons-lang for properly escaping xml in changelog.xml files
1 parent 775ae4e commit 7c67b46

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

src/main/java/hudson/plugins/perforce/PerforceChangeLogSet.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import java.util.Collections;
1414
import java.util.Iterator;
1515
import java.util.List;
16+
import org.apache.commons.lang.StringEscapeUtils;
1617
import org.kohsuke.stapler.framework.io.WriterOutputStream;
1718

1819
/**
@@ -69,27 +70,27 @@ public static void saveToChangeLog(OutputStream outputStream, List<Changelist> c
6970
for (Changelist change : changes) {
7071
stream.println("\t<entry>");
7172
stream.println("\t\t<changenumber>" + change.getChangeNumber() + "</changenumber>");
72-
stream.println("\t\t<date>" + Util.xmlEscape(PerforceChangeLogParser.javaDateToStringDate(change.getDate())) + "</date>");
73-
stream.println("\t\t<description>" + Util.xmlEscape(change.getDescription()) + "</description>");
74-
stream.println("\t\t<user>" + Util.xmlEscape(change.getUser()) + "</user>");
75-
stream.println("\t\t<workspace>" + Util.xmlEscape(change.getWorkspace()) + "</workspace>");
73+
stream.println("\t\t<date>" + StringEscapeUtils.escapeXml(PerforceChangeLogParser.javaDateToStringDate(change.getDate())) + "</date>");
74+
stream.println("\t\t<description>" + StringEscapeUtils.escapeXml(change.getDescription()) + "</description>");
75+
stream.println("\t\t<user>" + StringEscapeUtils.escapeXml(change.getUser()) + "</user>");
76+
stream.println("\t\t<workspace>" + StringEscapeUtils.escapeXml(change.getWorkspace()) + "</workspace>");
7677
stream.println("\t\t<files>");
7778
for (Changelist.FileEntry entry : change.getFiles()) {
7879
stream.println("\t\t\t<file>");
79-
stream.println("\t\t\t\t<name>" + Util.xmlEscape(entry.getFilename()) + "</name>");
80-
stream.println("\t\t\t\t<workspacePath>" + Util.xmlEscape(entry.getWorkspacePath()) + "</workspacePath>");
81-
stream.println("\t\t\t\t<rev>" + Util.xmlEscape(entry.getRevision()) + "</rev>");
82-
stream.println("\t\t\t\t<changenumber>" + Util.xmlEscape(entry.getChangenumber()) + "</changenumber>");
80+
stream.println("\t\t\t\t<name>" + StringEscapeUtils.escapeXml(entry.getFilename()) + "</name>");
81+
stream.println("\t\t\t\t<workspacePath>" + StringEscapeUtils.escapeXml(entry.getWorkspacePath()) + "</workspacePath>");
82+
stream.println("\t\t\t\t<rev>" + StringEscapeUtils.escapeXml(entry.getRevision()) + "</rev>");
83+
stream.println("\t\t\t\t<changenumber>" + StringEscapeUtils.escapeXml(entry.getChangenumber()) + "</changenumber>");
8384
stream.println("\t\t\t\t<action>" + entry.getAction() + "</action>");
8485
stream.println("\t\t\t</file>");
8586
}
8687
stream.println("\t\t</files>");
8788
stream.println("\t\t<jobs>");
8889
for (Changelist.JobEntry entry : change.getJobs()) {
8990
stream.println("\t\t\t<job>");
90-
stream.println("\t\t\t\t<name>" + Util.xmlEscape(entry.getJob()) + "</name>");
91-
stream.println("\t\t\t\t<description>" + Util.xmlEscape(entry.getDescription()) + "</description>");
92-
stream.println("\t\t\t\t<status>" + Util.xmlEscape(entry.getStatus()) + "</status>");
91+
stream.println("\t\t\t\t<name>" + StringEscapeUtils.escapeXml(entry.getJob()) + "</name>");
92+
stream.println("\t\t\t\t<description>" + StringEscapeUtils.escapeXml(entry.getDescription()) + "</description>");
93+
stream.println("\t\t\t\t<status>" + StringEscapeUtils.escapeXml(entry.getStatus()) + "</status>");
9394
stream.println("\t\t\t</job>");
9495
}
9596
stream.println("\t\t</jobs>");

src/test/java/hudson/plugins/perforce/PerforceChangeLogParserTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public void testSaveAndLoadChangeLogSet() throws Exception {
2727
List<Changelist> changes = new ArrayList<Changelist>();
2828
Changelist cl = new Changelist();
2929
cl.setChangeNumber(1000);
30-
cl.setDescription("test change");
30+
cl.setDescription("test change <this is broken XML&>");
3131
cl.setUser("test.user");
3232
cl.setWorkspace("test_workspace");
3333
List<Changelist.FileEntry> files = new ArrayList<Changelist.FileEntry>();
@@ -53,7 +53,7 @@ public void testSaveAndLoadChangeLogSet() throws Exception {
5353
jobEntry.setStatus("submitted");
5454
jobs.add(jobEntry);
5555
jobEntry = new Changelist.JobEntry();
56-
jobEntry.setDescription("test job2");
56+
jobEntry.setDescription("test job2 <!--Contains some nonsense-->\n<[[ like, really broken ]]>\n");
5757
jobEntry.setJob("test-job2");
5858
jobEntry.setStatus("rejected");
5959
jobs.add(jobEntry);

0 commit comments

Comments
 (0)