From 5be0982abd115b2d18f0c4f6f27319265d4b42f9 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Tue, 20 Aug 2024 13:21:14 +0200 Subject: [PATCH] Do some naive HTML escaping Some errors can contain XML and part of the message uses HTML blocks so we need to take care of that. --- .../githubactions/WorkflowReportFormatter.java | 16 ++++++++++++++++ .../WorkflowReportFormatter/checkRunReport.md | 8 ++++---- .../WorkflowReportFormatter/commentReport.md | 8 ++++---- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/WorkflowReportFormatter.java b/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/WorkflowReportFormatter.java index 6e4b230..78732af 100644 --- a/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/WorkflowReportFormatter.java +++ b/build-reporter-github-actions/src/main/java/io/quarkus/bot/buildreporter/githubactions/WorkflowReportFormatter.java @@ -7,6 +7,7 @@ import io.quarkus.bot.buildreporter.githubactions.report.WorkflowReport; import io.quarkus.bot.buildreporter.githubactions.report.WorkflowReportJobIncludeStrategy; import io.quarkus.qute.CheckedTemplate; +import io.quarkus.qute.TemplateExtension; import io.quarkus.qute.TemplateInstance; @ApplicationScoped @@ -52,4 +53,19 @@ public static native TemplateInstance commentReport(WorkflowReport report, boole boolean includeStackTraces, boolean includeFailureLinks, WorkflowReportJobIncludeStrategy workflowReportJobIncludeStrategy); } + + @TemplateExtension + public class TemplateExtensions { + + /** + * This is very naive and just designed to not break the markdown. + */ + public static String escapeHtml(String html) { + if (html == null || html.isBlank()) { + return html; + } + + return html.replace("&", "&").replace("<", "<").replace(">", ">"); + } + } } diff --git a/build-reporter-github-actions/src/main/resources/templates/WorkflowReportFormatter/checkRunReport.md b/build-reporter-github-actions/src/main/resources/templates/WorkflowReportFormatter/checkRunReport.md index 73ce196..84173a7 100644 --- a/build-reporter-github-actions/src/main/resources/templates/WorkflowReportFormatter/checkRunReport.md +++ b/build-reporter-github-actions/src/main/resources/templates/WorkflowReportFormatter/checkRunReport.md @@ -34,7 +34,7 @@ ``` {#for failure : module.testFailures} -

{failure.fullName}{#if failure.failureErrorLine} line {failure.failureErrorLine}{/if}{#if develocityEnabled && develocityUrl} - History{/if}{#if includeFailureLinks} - Source on GitHub - 🠅{/if}

+

{failure.fullName.escapeHtml}{#if failure.failureErrorLine} line {failure.failureErrorLine}{/if}{#if develocityEnabled && develocityUrl} - History{/if}{#if includeFailureLinks} - Source on GitHub - 🠅{/if}

{#if (failure.abbreviatedFailureDetail && includeStackTraces) || (report.sameRepository && failure.failureErrorLine)}
@@ -53,7 +53,7 @@ {/for} {#else if module.projectReportFailure} -

{module.projectReportFailure}

+

{module.projectReportFailure.escapeHtml}

{#else}

We were unable to extract a useful error message.

@@ -77,10 +77,10 @@ #### :package: {module.name ? module.name : "Root project"} {#for flakyTest : module.flakyTests} -

{flakyTest.fullName}{#if develocityEnabled && develocityUrl} - History{/if}

+

{flakyTest.fullName.escapeHtml}{#if develocityEnabled && develocityUrl} - History{/if}

{#for flake : flakyTest.flakes} -- `{flake.message}`{#if flake.type} - {flake.type}{/if} +- `{flake.message}`{#if flake.type} - `{flake.type}`{/if} {#if flake.abbreviatedStackTrace.trim && includeStackTraces}
diff --git a/build-reporter-github-actions/src/main/resources/templates/WorkflowReportFormatter/commentReport.md b/build-reporter-github-actions/src/main/resources/templates/WorkflowReportFormatter/commentReport.md index 827cfc0..ecc3e02 100644 --- a/build-reporter-github-actions/src/main/resources/templates/WorkflowReportFormatter/commentReport.md +++ b/build-reporter-github-actions/src/main/resources/templates/WorkflowReportFormatter/commentReport.md @@ -66,7 +66,7 @@ Full information is available in the [Build summary check run]({checkRun.htmlUrl {#if module.testFailures} {#for failure : module.testFailures} -

{failure.fullName}{#if failure.failureErrorLine} line {failure.failureErrorLine}{/if}{#if develocityEnabled && develocityUrl} - History{/if}{#if includeFailureLinks} - {#if checkRun && failure.failureDetail}More details - {/if}Source on GitHub{/if}

+

{failure.fullName.escapeHtml}{#if failure.failureErrorLine} line {failure.failureErrorLine}{/if}{#if develocityEnabled && develocityUrl} - History{/if}{#if includeFailureLinks} - {#if checkRun && failure.failureDetail}More details - {/if}Source on GitHub{/if}

{#if failure.abbreviatedFailureDetail && includeStackTraces}
@@ -80,7 +80,7 @@ Full information is available in the [Build summary check run]({checkRun.htmlUrl {/for} {#else if module.projectReportFailure} -

{module.projectReportFailure}

+

{module.projectReportFailure.escapeHtml}

{#else}

We were unable to extract a useful error message.

@@ -120,10 +120,10 @@ It should be safe to merge provided you have a look at the other checks in the s #### :package: {module.name ? module.name : "Root project"} {#for flakyTest : module.flakyTests} -

{flakyTest.fullName}{#if develocityEnabled && develocityUrl} - History{/if}

+

{flakyTest.fullName.escapeHtml}{#if develocityEnabled && develocityUrl} - History{/if}

{#for flake : flakyTest.flakes} -- `{flake.message}`{#if flake.type} - {flake.type}{/if} +- `{flake.message}`{#if flake.type} - `{flake.type}`{/if} {#if flake.abbreviatedStackTrace.trim && includeStackTraces}