|
20 | 20 | import java.io.FileWriter;
|
21 | 21 | import java.io.IOException;
|
22 | 22 | import java.util.ArrayList;
|
| 23 | +import java.util.Arrays; |
23 | 24 | import java.util.Collections;
|
24 | 25 | import java.util.Comparator;
|
25 | 26 | import java.util.List;
|
@@ -55,7 +56,7 @@ public class ChangelogGenerator {
|
55 | 56 | private static final Comparator<Issue> TITLE_COMPARATOR = Comparator.comparing(Issue::getTitle,
|
56 | 57 | String.CASE_INSENSITIVE_ORDER);
|
57 | 58 |
|
58 |
| - private static final Pattern ghUserMentionPattern = Pattern.compile("(^|[^\\w`])(@[\\w-]+)"); |
| 59 | + private static final List<Escape> escapes = Arrays.asList(gitHubUserMentions(), htmlTags()); |
59 | 60 |
|
60 | 61 | private final GitHubService service;
|
61 | 62 |
|
@@ -160,7 +161,9 @@ private void sort(IssueSort sort, List<Issue> issues) {
|
160 | 161 |
|
161 | 162 | private String getFormattedIssue(Issue issue) {
|
162 | 163 | String title = issue.getTitle();
|
163 |
| - title = ghUserMentionPattern.matcher(title).replaceAll("$1`$2`"); |
| 164 | + for (Escape escape : escapes) { |
| 165 | + title = escape.apply(title); |
| 166 | + } |
164 | 167 | return String.format("- %s %s%n", title, getLinkToIssue(issue));
|
165 | 168 | }
|
166 | 169 |
|
@@ -236,4 +239,36 @@ private void writeContentToFile(String content, String path) throws IOException
|
236 | 239 | FileCopyUtils.copy(content, new FileWriter(new File(path)));
|
237 | 240 | }
|
238 | 241 |
|
| 242 | + private static Escape gitHubUserMentions() { |
| 243 | + return new PatternEscape(Pattern.compile("(^|[^\\w`])(@[\\w-]+)"), "$1`$2`"); |
| 244 | + } |
| 245 | + |
| 246 | + private static Escape htmlTags() { |
| 247 | + return new PatternEscape(Pattern.compile("(^|[^\\w`])(<[\\w\\-/<>]+>)"), "$1`$2`"); |
| 248 | + } |
| 249 | + |
| 250 | + private interface Escape { |
| 251 | + |
| 252 | + String apply(String input); |
| 253 | + |
| 254 | + } |
| 255 | + |
| 256 | + private static final class PatternEscape implements Escape { |
| 257 | + |
| 258 | + private final Pattern pattern; |
| 259 | + |
| 260 | + private final String replacement; |
| 261 | + |
| 262 | + private PatternEscape(Pattern pattern, String replacement) { |
| 263 | + this.pattern = pattern; |
| 264 | + this.replacement = replacement; |
| 265 | + } |
| 266 | + |
| 267 | + @Override |
| 268 | + public String apply(String input) { |
| 269 | + return this.pattern.matcher(input).replaceAll(this.replacement); |
| 270 | + } |
| 271 | + |
| 272 | + } |
| 273 | + |
239 | 274 | }
|
0 commit comments