From 2d22fcc831c23676b8a082ee9d0ee888406b6b28 Mon Sep 17 00:00:00 2001 From: Dzmitry Yurtsevich Date: Thu, 27 Jun 2024 10:45:56 +0200 Subject: [PATCH] Replace dollar character by appropriate HTML entity (#45) fix: Replace dollar character by appropriate HTML entity, otherwise it's treated as special RegExp character Refs: #42 --- .../extension/pdf/exporter/util/HtmlProcessor.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/HtmlProcessor.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/HtmlProcessor.java index 036324b..b791deb 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/HtmlProcessor.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/HtmlProcessor.java @@ -156,6 +156,9 @@ public HtmlProcessor(FileResourceProvider fileResourceProvider, LocalizationSett } public String processHtmlForPDF(@NotNull String html, @NotNull ExportParams exportParams, @NotNull List selectedRoleEnumValues) { + // Replace all dollar-characters in HTML document before applying any regular expressions, as it has special meaning there + html = html.replaceAll("\\$", "$"); + html = removePd4mlTags(html); html = html.replace("/ria/images/enums/", "/icons/default/enums/"); html = html.replace("


", "
"); @@ -559,13 +562,13 @@ private String removePd4mlTags(@NotNull String html) { @SuppressWarnings({"java:S5869", "java:S6019"}) String properTableHeads(@NotNull String html) { // Searches for all subsequent table rows (-tags) inside which contain -tags - // followed by a row which doesn't contain . + // followed by a row which doesn't contain (or closing tag). // There are 2 groups in this regexp, first one is unnamed, containing and -tags containing -tags, // second one is named ("header") and contains those -tags which include -tags. The regexp is ending // by positive lookahead "(?=-tags containing -tags and move it from into , // for table headers to repeat on each page. - Pattern pattern = Pattern.compile("([^<]*(?
[^<]*[^<]*(?
[^<]*