Skip to content

Commit

Permalink
fix: capture more element expressions
Browse files Browse the repository at this point in the history
Signed-off-by: Andres Correa Casablanca <[email protected]>
  • Loading branch information
castarco committed Feb 15, 2024
1 parent e6b2653 commit f8e57e5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions core.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ export const updateSriHashes = async (logger, distDir, content, h) => {
{
t: 'Script',
regex:
/<script(?<attrs>(\s+[a-z][a-z0-9\-_]*(=('[^']*?'|"[^"]*?"))?)*?)\s*>(?<content>[\s\S]*?)<\/\s*script>/gi,
/<script(?<attrs>(\s+[a-z][a-z0-9\-_]*(=('[^']*?'|"[^"]*?"))?)*?)\s*>(?<content>[\s\S]*?)<\/\s*script\s*>/gi,

Check failure

Code scanning / CodeQL

Bad HTML filtering regexp High

This regular expression does not match script end tags like </script\t\n bar>.
replacer: scriptReplacer,
hasContent: true,
attrsRegex: undefined,
},
{
t: 'Style',
regex:
/<style(?<attrs>(\s+[a-z][a-z0-9\-_]*(=('[^']*?'|"[^"]*?"))?)*?)\s*>(?<content>[\s\S]*?)<\/\s*style>/gi,
/<style(?<attrs>(\s+[a-z][a-z0-9\-_]*(=('[^']*?'|"[^"]*?"))?)*?)\s*>(?<content>[\s\S]*?)<\/\s*style\s*>/gi,
replacer: styleReplacer,
hasContent: true,
attrsRegex: undefined,
Expand Down
4 changes: 2 additions & 2 deletions tests/core.test.mts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ describe('updateSriHashes', () => {
<title>My Test Page</title>
</head>
<body>
<script type="module" src="/core.mjs" integrity="sha256-wX1IJSSLt2R7euylvbWLqrh+JTZCJlJleWlAUMjY6U8="></script>
<script type="module" src="/core.mjs" integrity="sha256-GlpkA8WAeGW9d6jr04eDhYbHj9yNtaB4+Q/5HwOc05M="></script>
</body>
</html>`

Expand All @@ -205,7 +205,7 @@ describe('updateSriHashes', () => {

expect(updated).toEqual(expected)
expect(h.extScriptHashes.size).toBe(1)
expect(h.extScriptHashes.has('sha256-wX1IJSSLt2R7euylvbWLqrh+JTZCJlJleWlAUMjY6U8=')).toBe(true)
expect(h.extScriptHashes.has('sha256-GlpkA8WAeGW9d6jr04eDhYbHj9yNtaB4+Q/5HwOc05M=')).toBe(true)
expect(h.inlineScriptHashes.size).toBe(0)
expect(h.inlineStyleHashes.size).toBe(0)
expect(h.extStyleHashes.size).toBe(0)
Expand Down

0 comments on commit f8e57e5

Please sign in to comment.