Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: added new rule “attr-space-between”#1459

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
actengage wants to merge1 commit intohtmlhint:main
base:main
Choose a base branch
Loading
fromActiveEngagement:master

Conversation

actengage
Copy link

@actengageactengage commentedAug 12, 2024
edited by coliff
Loading

Consider the following the HTML:

<divid="bar"class="foo"></div>

The following error is what I get in the current version of HTMLHint.

Special characters must be escaped : [ &lt; ].Special characters must be escaped : [ &gt; ].Tag must be paired, no start tag: [ &lt;/div&gt; ]

Theattr-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:

Attribute "class" must be separated with a space

Proposed changes:

Change this Regex inhtmlparser.ts:

constregTag=// eslint-disable-next-line no-control-regex/<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s+[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g

To the following:

constregTag=// eslint-disable-next-line no-control-regex/<(?:\/([^\s>]+)\s*|!--([\s\S]*?)--|!([^>]*?)|([\w\-:]+)((?:\s*[^\s"'>\/=\x00-\x0F\x7F\x80-\x9F]+(?:\s*=\s*(?:"[^"]*"|'[^']*'|[^\s"'>]*))?)*?)\s*(\/?))>/g

I also added theattr-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.

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.
@github-actionsgithub-actionsbot added coreRelates to HTMLHint's core APIs and features test labelsAug 12, 2024
@@ -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

This part of the regular expression may cause exponential backtracking on strings starting with '<-' and containing many repetitions of '!'.
@coliff
Copy link
Member

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.

@coliffcoliff added keep-unstaleThe issue will not be marked as stale by the stale-bot ruleRelates to HTMLHint's core rules labelsAug 26, 2024
@actengage
Copy link
Author

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.

@coliff
Copy link
Member

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.

@coliff
Copy link
Member

There are conflicts in the branch now so moving this to Draft status.

@coliffcoliff marked this pull request as draftMay 8, 2025 02:43
@coliffcoliff requested review fromcoliff and removed request forthedaviddiasJune 6, 2025 05:27
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@coliffcoliffAwaiting requested review from coliff

@thedaviddiasthedaviddiasAwaiting requested review from thedaviddiasthedaviddias will be requested when the pull request is marked ready for reviewthedaviddias is a code owner

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
coreRelates to HTMLHint's core APIs and featureskeep-unstaleThe issue will not be marked as stale by the stale-botruleRelates to HTMLHint's core rulestest
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@actengage@coliff

[8]ページ先頭

©2009-2025 Movatter.jp