Skip to content

Commit

Permalink
Merge pull request #214 from gsmet/html-escaping
Browse files Browse the repository at this point in the history
Do some naive HTML escaping
  • Loading branch information
gsmet authored Aug 20, 2024
2 parents c56610c + 5be0982 commit ff12422
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
```

{#for failure : module.testFailures}
<p>✖ <code>{failure.fullName}</code>{#if failure.failureErrorLine} line <code>{failure.failureErrorLine}</code>{/if}{#if develocityEnabled && develocityUrl} - <a href="{develocityUrl}scans/tests?tests.container={failure.fullClassName}&tests.test={failure.name}">History</a>{/if}{#if includeFailureLinks} <a id="test-failure-{failure.fullClassName.toLowerCase}-{failure_count}"></a> - <a href="{failure.shortenedFailureUrl}">Source on GitHub</a> - <a href="#user-content-build-summary-top">🠅</a>{/if}</p>
<p>✖ <code>{failure.fullName.escapeHtml}</code>{#if failure.failureErrorLine} line <code>{failure.failureErrorLine}</code>{/if}{#if develocityEnabled && develocityUrl} - <a href="{develocityUrl}scans/tests?tests.container={failure.fullClassName}&tests.test={failure.name}">History</a>{/if}{#if includeFailureLinks} <a id="test-failure-{failure.fullClassName.toLowerCase}-{failure_count}"></a> - <a href="{failure.shortenedFailureUrl}">Source on GitHub</a> - <a href="#user-content-build-summary-top">🠅</a>{/if}</p>

{#if (failure.abbreviatedFailureDetail && includeStackTraces) || (report.sameRepository && failure.failureErrorLine)}
<details>
Expand All @@ -53,7 +53,7 @@

{/for}
{#else if module.projectReportFailure}
<p>✖ <code>{module.projectReportFailure}</code></p>
<p>✖ <code>{module.projectReportFailure.escapeHtml}</code></p>

{#else}
<p>We were unable to extract a useful error message.</p>
Expand All @@ -77,10 +77,10 @@
#### :package: {module.name ? module.name : "Root project"}

{#for flakyTest : module.flakyTests}
<p>✖ <code>{flakyTest.fullName}</code>{#if develocityEnabled && develocityUrl} - <a href="{develocityUrl}scans/tests?tests.container={flakyTest.fullClassName}&tests.test={flakyTest.name}">History</a>{/if}</p>
<p>✖ <code>{flakyTest.fullName.escapeHtml}</code>{#if develocityEnabled && develocityUrl} - <a href="{develocityUrl}scans/tests?tests.container={flakyTest.fullClassName}&tests.test={flakyTest.name}">History</a>{/if}</p>

{#for flake : flakyTest.flakes}
- `{flake.message}`{#if flake.type} - <code>{flake.type}</code>{/if}
- `{flake.message}`{#if flake.type} - `{flake.type}`{/if}

{#if flake.abbreviatedStackTrace.trim && includeStackTraces}
<details>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Full information is available in the [Build summary check run]({checkRun.htmlUrl

{#if module.testFailures}
{#for failure : module.testFailures}
<p>✖ <code>{failure.fullName}</code>{#if failure.failureErrorLine} line <code>{failure.failureErrorLine}</code>{/if}{#if develocityEnabled && develocityUrl} - <a href="{develocityUrl}scans/tests?tests.container={failure.fullClassName}&tests.test={failure.name}">History</a>{/if}{#if includeFailureLinks} - {#if checkRun && failure.failureDetail}<a href="{checkRun.htmlUrl}#user-content-test-failure-{failure.fullClassName.toLowerCase}-{failure_count}">More details</a> - {/if}<a href="{failure.shortenedFailureUrl}">Source on GitHub</a>{/if}</p>
<p>✖ <code>{failure.fullName.escapeHtml}</code>{#if failure.failureErrorLine} line <code>{failure.failureErrorLine}</code>{/if}{#if develocityEnabled && develocityUrl} - <a href="{develocityUrl}scans/tests?tests.container={failure.fullClassName}&tests.test={failure.name}">History</a>{/if}{#if includeFailureLinks} - {#if checkRun && failure.failureDetail}<a href="{checkRun.htmlUrl}#user-content-test-failure-{failure.fullClassName.toLowerCase}-{failure_count}">More details</a> - {/if}<a href="{failure.shortenedFailureUrl}">Source on GitHub</a>{/if}</p>

{#if failure.abbreviatedFailureDetail && includeStackTraces}
<details>
Expand All @@ -80,7 +80,7 @@ Full information is available in the [Build summary check run]({checkRun.htmlUrl

{/for}
{#else if module.projectReportFailure}
<p>✖ <code>{module.projectReportFailure}</code></p>
<p>✖ <code>{module.projectReportFailure.escapeHtml}</code></p>

{#else}
<p>We were unable to extract a useful error message.</p>
Expand Down Expand Up @@ -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}
<p>✖ <code>{flakyTest.fullName}</code>{#if develocityEnabled && develocityUrl} - <a href="{develocityUrl}scans/tests?tests.container={flakyTest.fullClassName}&tests.test={flakyTest.name}">History</a>{/if}</p>
<p>✖ <code>{flakyTest.fullName.escapeHtml}</code>{#if develocityEnabled && develocityUrl} - <a href="{develocityUrl}scans/tests?tests.container={flakyTest.fullClassName}&tests.test={flakyTest.name}">History</a>{/if}</p>

{#for flake : flakyTest.flakes}
- `{flake.message}`{#if flake.type} - <code>{flake.type}</code>{/if}
- `{flake.message}`{#if flake.type} - `{flake.type}`{/if}

{#if flake.abbreviatedStackTrace.trim && includeStackTraces}
<details>
Expand Down

0 comments on commit ff12422

Please sign in to comment.