Skip to content

Commit d746dd9

Browse files
Copilotswissspidy
andauthored
Decode HTML entities in action log output (#479)
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Pascal Birchler <pascalb@google.com>
1 parent 24addfb commit d746dd9

5 files changed

Lines changed: 100 additions & 6 deletions

File tree

dist/index.js

Lines changed: 53 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { context } from '@actions/github';
1111
import { existsSync, readFileSync } from 'node:fs';
1212
import { PRCommentManager } from './pr-comment-manager';
1313
import { PRCommentFormatter, CheckResult } from './pr-comment-formatter';
14+
import { decodeHtmlEntities } from './utils';
1415

1516
const args = process.argv.slice(2);
1617

@@ -49,7 +50,7 @@ for (let i = 0; i < fileContents.length - 1; i++) {
4950
result.type === 'ERROR' || process.env.STRICT === 'true'
5051
? error
5152
: warning;
52-
func(result.message, {
53+
func(decodeHtmlEntities(result.message), {
5354
title: result.code,
5455
file: fileName,
5556
startLine: result.line,

src/pr-comment-formatter.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { decodeHtmlEntities } from './utils';
2+
13
export interface CheckResult {
24
line: number;
35
column: number;
@@ -208,7 +210,11 @@ ${sections.join('\n\n')}`;
208210

209211
const rows = results.map(result => {
210212
const line = result.line > 0 ? `\`${result.line}\`` : '`0`';
211-
return this.tableRow([line, result.code, result.message]);
213+
return this.tableRow([
214+
line,
215+
result.code,
216+
decodeHtmlEntities(result.message),
217+
]);
212218
});
213219

214220
return [header, separator, ...rows].join('\n');

src/utils.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Decodes HTML entities in a string.
3+
* This handles common HTML entities found in WordPress Plugin Check output.
4+
*
5+
* @param text - The text containing HTML entities
6+
* @returns The decoded text
7+
*/
8+
export function decodeHtmlEntities(text: string): string {
9+
const namedEntities: Record<string, string> = {
10+
'&quot;': '"',
11+
'&apos;': "'",
12+
'&amp;': '&',
13+
'&lt;': '<',
14+
'&gt;': '>',
15+
'&nbsp;': ' ',
16+
};
17+
18+
return text.replace(
19+
/&(?:#x([0-9a-fA-F]+)|#(\d+)|([a-zA-Z]+));/g,
20+
(match, hex, dec, named) => {
21+
if (hex) {
22+
// Hexadecimal entity
23+
return String.fromCharCode(parseInt(hex, 16));
24+
}
25+
if (dec) {
26+
// Decimal entity
27+
return String.fromCharCode(parseInt(dec, 10));
28+
}
29+
if (named && namedEntities[`&${named};`]) {
30+
// Named entity
31+
return namedEntities[`&${named};`];
32+
}
33+
// Unknown entity, return as-is
34+
return match;
35+
},
36+
);
37+
}

0 commit comments

Comments
 (0)