Skip to content

Commit 1838b76

Browse files
committedJan 27, 2023
1807: Escape HTML in source code hosting provider's web UI as required
Reviewed-by: erikj
1 parent e57d416 commit 1838b76

File tree

6 files changed

+20
-16
lines changed

6 files changed

+20
-16
lines changed
 

‎bots/censussync/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ dependencies {
4444
implementation project(':storage')
4545
implementation project(':xml')
4646
implementation project(':metrics')
47+
implementation project(':bots:common')
48+
implementation project(':jbs')
49+
implementation project(':jcheck')
4750

4851
testImplementation project(':test')
4952
}

‎bots/censussync/src/main/java/module-info.java

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@
3131
requires java.logging;
3232
requires java.xml;
3333
requires java.net.http;
34+
requires org.openjdk.skara.jcheck;
35+
requires org.openjdk.skara.jbs;
36+
requires org.openjdk.skara.bots.common;
3437

3538
provides org.openjdk.skara.bot.BotFactory with org.openjdk.skara.bots.censussync.CensusSyncBotFactory;
3639
}

‎bots/censussync/src/main/java/org/openjdk/skara/bots/censussync/CensusSyncSplitBot.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
2424
package org.openjdk.skara.bots.censussync;
2525

2626
import org.openjdk.skara.bot.*;
27+
import org.openjdk.skara.bots.common.BotUtils;
2728
import org.openjdk.skara.forge.HostedRepository;
2829
import org.openjdk.skara.network.RestRequest;
2930
import org.openjdk.skara.vcs.*;
@@ -77,10 +78,6 @@ private static PrintWriter newPrintWriter(Path p) throws IOException {
7778
return new PrintWriter(Files.newBufferedWriter(p));
7879
}
7980

80-
private static String escape(String s) {
81-
return s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
82-
}
83-
8481
private static List<Path> syncVersion(Element census, Path to) throws IOException {
8582
var date = ZonedDateTime.parse(XML.attribute(census, "time"));
8683
var timestamp = date.toInstant();
@@ -133,7 +130,7 @@ private static List<Path> syncGroups(Element census, Path to) throws IOException
133130
var filename = dir.resolve(name + ".xml");
134131
try (var file = newPrintWriter(filename)) {
135132
file.format("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>%n");
136-
file.format("<group name=\"%s\" full-name=\"%s\">%n", name, escape(fullName));
133+
file.format("<group name=\"%s\" full-name=\"%s\">%n", name, BotUtils.escape(fullName));
137134
file.format(" <lead username=\"%s\" />%n", lead);
138135
for (var member : members) {
139136
file.format(" <member username=\"%s\" />%n", member);
@@ -191,7 +188,7 @@ private static List<Path> syncProjects(Element census, Path to) throws IOExcepti
191188
var filename = dir.resolve(name + ".xml");
192189
try (var file = newPrintWriter(filename)) {
193190
file.format("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>%n");
194-
file.format("<project name=\"%s\" full-name=\"%s\" sponsor=\"%s\">%n", name, escape(fullName), sponsor);
191+
file.format("<project name=\"%s\" full-name=\"%s\" sponsor=\"%s\">%n", name, BotUtils.escape(fullName), sponsor);
195192
file.format(" <lead username=\"%s\" since=\"0\" />%n", lead);
196193

197194
for (var reviewer : reviewers) {

‎bots/censussync/src/main/java/org/openjdk/skara/bots/censussync/CensusSyncUnifyBot.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -24,6 +24,7 @@
2424
package org.openjdk.skara.bots.censussync;
2525

2626
import org.openjdk.skara.bot.*;
27+
import org.openjdk.skara.bots.common.BotUtils;
2728
import org.openjdk.skara.census.Census;
2829
import org.openjdk.skara.forge.*;
2930
import org.openjdk.skara.vcs.*;
@@ -49,10 +50,6 @@ public class CensusSyncUnifyBot implements Bot, WorkItem {
4950
this.last = null;
5051
}
5152

52-
private static String escape(String s) {
53-
return s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
54-
}
55-
5653
@Override
5754
public boolean concurrentWith(WorkItem other) {
5855
if (!(other instanceof CensusSyncUnifyBot)) {
@@ -102,7 +99,7 @@ public Collection<WorkItem> run(Path scratch) {
10299
}
103100
for (var group : census.groups()) {
104101
file.println("<group name=\"" + group.name() + "\">");
105-
file.println(" <full-name>" + escape(group.fullName()) + "</full-name>");
102+
file.println(" <full-name>" + BotUtils.escape(group.fullName()) + "</full-name>");
106103
file.println(" <person ref=\"" + group.lead().username() + "\" role=\"lead\" />");
107104
for (var member : group.members()) {
108105
if (!member.username().equals(group.lead().username())) {
@@ -113,7 +110,7 @@ public Collection<WorkItem> run(Path scratch) {
113110
}
114111
for (var project : census.projects()) {
115112
file.println("<project name=\"" + project.name() + "\">");
116-
file.println(" <full-name>" + escape(project.fullName()) + "</full-name>");
113+
file.println(" <full-name>" + BotUtils.escape(project.fullName()) + "</full-name>");
117114
file.println(" <sponsor ref=\"" + project.sponsor().name() + "\" />");
118115

119116
var roles = project.roles(version);

‎bots/common/src/main/java/org/openjdk/skara/bots/common/BotUtils.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -53,4 +53,8 @@ public static Optional<JdkVersion> getVersion(PullRequest pr) {
5353
}
5454
return JdkVersion.parse(version);
5555
}
56+
57+
public static String escape(String s) {
58+
return s.replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
59+
}
5660
}

‎bots/pr/src/main/java/org/openjdk/skara/bots/pr/CheckRun.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ private String getStatusMessage(PullRequestCheckIssueVisitor visitor,
665665
progressBody.append("](");
666666
progressBody.append(iss.get().webUrl());
667667
progressBody.append("): ");
668-
progressBody.append(iss.get().title());
668+
progressBody.append(BotUtils.escape(iss.get().title()));
669669
var issueType = iss.get().properties().get("issuetype");
670670
if (issueType != null && "CSR".equals(issueType.asString())) {
671671
progressBody.append(" (**CSR**)");

1 commit comments

Comments
 (1)

openjdk-notifier[bot] commented on Jan 27, 2023

@openjdk-notifier[bot]
Please sign in to comment.