Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict regexes #40

Merged
merged 6 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 28 additions & 7 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,43 @@ module.exports = util = {
*/
matchers: [
// script with quoted src
{ pattern: /(<script\s[^>]*?src=["'])([\s\S]+?)(["'][^>]*>\s*<\/script>)/gi, fallback: true },
{
pattern: /(<script\s[^>]*?src\s*=\s*["'])([^"']+)(["'][^>]*>\s*<\/script\s*>)/gi,
fallback: true
},
// script with unquoted src
{ pattern: /(<script\s[^>]*?src=)([\s\S]+?)((?:>|\s[^>]*>)\s*<\/script>)/gi, fallback: true },
{
pattern: /(<script\s[^>]*?src\s*=\s*)([^\s"'>]+)([^>]*>\s*<\/script>)/gi,
fallback: true
},

// link with quoted href and optional end tag
{ pattern: /(<link\s[^>]*?href=["'])([\s\S]+?)(["'][^>]*>(?:\s*<\/link>)?)/gi, fallback: true },
{
pattern: /(<link\s[^>]*?href\s*=\s*["'])([^"']+)(["'][^>]*>(?:\s*<\/link\s*>)?)/gi,
fallback: true
},
// link with unquoted href and optional end tag
{ pattern: /(<link\s[^>]*?href=)([\s\S]+?)((?:>|\s[^>]*>)(?:\s*<\/link>)?)/gi, fallback: true },
{
pattern: /(<link\s[^>]*?href\s*=\s*)([^\s"'>]+)([^>]*>(?:\s*<\/link\s*>)?)/gi,
fallback: true
},

// img with quoted src
{ pattern: /(<img\s[^>]*?src=["'])(.+?)(["'][^>]*>)/gi, fallback: false },
{
pattern: /(<img\s[^>]*?src\s*=\s*["'])([^"']+)(["'][^>]*>)/gi,
fallback: false
},
// img with unquoted src
{ pattern: /(<img\s[^>]*?src=)(.+?)((?:>|\s[^>]*>))/gi, fallback: false },
{
pattern: /(<img\s[^>]*?src\s*=\s*)([^\s"'>]+)([^>]*>)/gi,
fallback: false
},

// URL matcher for CSS
{ pattern: /(url\(['"]?)(.+?)(['"]?\))/gi, fallback: false }
{
pattern: /(url\s*\(\s*['"]?)(.+?)(['"]?\s*\))/gi,
fallback: false
}
],

findFileInfo: function(url, opts) {
Expand Down
Loading