chore: re-enable and extend unescaped-html-literal eslint rule (#39832)

https://github.com/go-gitea/gitea/pull/38046 accidentally dropped
`gitea/unescaped-html-literal` from the eslint config, so it has been
off since. Raised in
https://github.com/go-gitea/gitea/pull/39829#issuecomment-6246720235.

- Re-enable the rule, exempting e2e tests like unit tests
- Detect tags anywhere in strings and template chunks, not only at the
start
- Allow `htmlRaw` templates, they escape like `html`
- Fix the existing violations, which escapes the heatmap tooltip and
shortcut keys
This commit is contained in:
silverwind authored and GitHub committed 2026-10-18 07:37:17 +00:00
1 parent a4908d4af4
commit 428d72d26f
8 files changed
+34 -11

No files matched your search

+1 -1
View File
@@ -85,7 +85,7 @@ function initDevtestAnsiRender(container: HTMLElement) {
...withSource(`first${esc}[Ksecond${esc}[2Jthird`),
...withSource(`cursor ${esc}[3Amovement, private ${esc}[?25lCSI, ${esc}]0;title${esc}\\titles, ${esc}Pquery${esc}\\strings, truncated${esc}[38;5;`),
...withSource('Reading... 10%\b\b\b100%'),
...withSource('<script>alert(1)</script> & "quotes", and a bare url https://example.com'),
...withSource('<script>alert(1)</script> & "quotes", and a bare url https://example.com'), // eslint-disable-line gitea/unescaped-html-literal -- plain text that the console must escape
' ',
`${esc}[31man unterminated color`,
'carries into the following lines',
+1 -1
View File
@@ -108,7 +108,7 @@ function showShortcutHelp() {
seenShortcuts.add(shortcutIdentifier);
let keysHtml = '';
for (const keys of shortcutKeys.split(' ')) {
keysHtml += `<kbd>${keys}</kbd> `;
keysHtml += html`<kbd>${keys}</kbd> `;
}
list.append(createElementFromHTML(html`<tr><td>${htmlRaw(keysHtml)}</td><td>${label}</td></tr>`));
}
+1 -2
View File
@@ -166,8 +166,7 @@ function attachTooltip(target: Element, content: Content | null = null): Instanc
let allowHTML = target.getAttribute('data-tooltip-render') === 'html';
if (!allowHTML && typeof content === 'string') {
content = htmlEscape(content);
content = content.replace(/\n/g, '<br>');
content = htmlEscape(content).split('\n').join(html`<br>`);
allowHTML = true;
}