-
-
Notifications
You must be signed in to change notification settings - Fork 386
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
feat: added new rule “attr-space-between” #1459
base: master
Are you sure you want to change the base?
Conversation
This rule ensures HTML tags with attributes must have spaces between them. Without this change, tags with attributes without the required space results in the parser interpretting the tag as text.
@@ -17,7 +17,7 @@ | |||
} | |||
parse(html) { | |||
const mapCdataTags = this._mapCdataTags; | |||
const regTag = /<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g; | |||
const regTag = /<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s*[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g; |
Check failure
Code scanning / CodeQL
Bad HTML filtering regexp High
@@ -17,7 +17,7 @@ | |||
} | |||
parse(html) { | |||
const mapCdataTags = this._mapCdataTags; | |||
const regTag = /<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g; | |||
const regTag = /<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s*[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g; |
Check failure
Code scanning / CodeQL
Inefficient regular expression High
@@ -30,7 +30,7 @@ | |||
} | |||
parse(html) { | |||
const mapCdataTags = this._mapCdataTags; | |||
const regTag = /<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g; | |||
const regTag = /<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s*[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g; |
Check failure
Code scanning / CodeQL
Bad HTML filtering regexp High
@@ -30,7 +30,7 @@ | |||
} | |||
parse(html) { | |||
const mapCdataTags = this._mapCdataTags; | |||
const regTag = /<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g; | |||
const regTag = /<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s*[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g; |
Check failure
Code scanning / CodeQL
Inefficient regular expression High
@@ -54,7 +54,7 @@ | |||
|
|||
const regTag = | |||
// eslint-disable-next-line no-control-regex | |||
/<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g | |||
/<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s*[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g |
Check failure
Code scanning / CodeQL
Bad HTML filtering regexp High
@@ -54,7 +54,7 @@ | |||
|
|||
const regTag = | |||
// eslint-disable-next-line no-control-regex | |||
/<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g | |||
/<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s*[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g |
Check failure
Code scanning / CodeQL
Inefficient regular expression High
Thanks for the PR! It looks good to me at a glance and could be an helpful addition to HTMLHint. We need @thedaviddias to review it. |
I didn't see this reply before. Thanks for looking into this. I'd love to get this approved in a new release so I don't have to use my fork in production. |
No problem. I'd like to see this added too but we need @thedaviddias to review it as he is the project owner but he hasn't been active here for a couple of years. |
Consider the following the HTML:
The following error is what I get in the current version of HTMLHint.
The
attr-space-between
rule ensures HTML tags with attributes must have spaces between them. Without this change, tags with attributes without the required space results in the parser interpreting the tag as text. The new error would be:Proposed changes:
Change this Regex in
htmlparser.ts
:To the following:
I also added the
attr-space-between
rule. The name of this rule could be subject to change, but this was the best I came up with. All tests pass with these changes, and docs were updated accordingly. Let me know what you think, and if I should make any additional changes.