Skip to content

Commit

Permalink
fix: Respect any character within script tags
Browse files Browse the repository at this point in the history
  • Loading branch information
d3xter666 committed Apr 10, 2024
1 parent d042458 commit af459f2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/linter/html/linter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export async function lintHtml(resourceName: string, contentStream: ReadStream):
const jsScriptTags = await extractJSScriptTags(contentStream);

jsScriptTags.forEach((tag) => {
const scriptContent = tag.textNodes?.map((tNode) => tNode.value).join("").trim();
const scriptContent = tag.textNodes?.map((tNode) => tNode.value).join("");
// Tags with src attribute do not parse and run inline code
const hasSrc = tag.attributes.some((attr) => {
return attr.name.value.toLowerCase() === "src";
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/linter/rules/CSPCompliance/NoInlineJS.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@

export const names = ["Kayla", "Bentley", "Gilligan"];
</script>

<script>
// This one should be reported!
</script>
</body>

</html>
11 changes: 10 additions & 1 deletion test/lib/linter/rules/snapshots/CSPCompliance.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,17 @@ Generated by [AVA](https://avajs.dev).
ruleId: 'ui5-linter-csp-unsafe-inline-script',
severity: 1,
},
{
column: 2,
fatal: undefined,
line: 55,
message: 'Use of unsafe inline script',
messageDetails: 'Content Security Policy (https://ui5.sap.com/1.120/#/topic/fe1a6dba940e479fb7c3bc753f92b28c)',
ruleId: 'ui5-linter-csp-unsafe-inline-script',
severity: 1,
},
],
warningCount: 5,
warningCount: 6,
},
]

Expand Down
Binary file modified test/lib/linter/rules/snapshots/CSPCompliance.ts.snap
Binary file not shown.

0 comments on commit af459f2

Please sign in to comment.