Skip to content

Commit

Permalink
fix(spec-char-escape): remove ampersand from spec-char-escape
Browse files Browse the repository at this point in the history
Ampersand is acceptable in HTML text, e. g. see: W3C validator

fix htmlhint#1382
  • Loading branch information
bebehr committed Feb 20, 2025
1 parent 00d4d69 commit 5b28af4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 3 additions & 1 deletion docs/user-guide/rules/spec-char-escape.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ Level: `error`
1. true: enable rule
2. false: disable rule

The following pattern are **not** considered violations:
The following patterns are **not** considered violations:

<!-- prettier-ignore -->
```html
<span>aaa&gt;bbb&lt;ccc</span>
<span>Steinway &amp; Sons, Q&amp;A</span>
<span>Steinway & Sons, Q&A</span>
```

The following pattern is considered violation:
Expand Down
3 changes: 1 addition & 2 deletions src/core/rules/spec-char-escape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ export default {
init(parser, reporter) {
parser.addListener('text', (event) => {
const raw = event.raw
// TODO: improve use-cases for &
const reSpecChar = /([<>])|( \& )/g
const reSpecChar = /([<>])/g
let match

while ((match = reSpecChar.exec(raw))) {
Expand Down
9 changes: 3 additions & 6 deletions test/rules/spec-char-escape.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,10 @@ describe(`Rules: ${ruleId}`, () => {
expect(messages[2].col).toBe(4)
})

it('Special characters: & should result in an error', () => {
const code = '<p>Steinway & Sons</p>'
it('Special characters: normal & should not result in an error', () => {
const code = '<p>Steinway & Sons Q&A</p>'
const messages = HTMLHint.verify(code, ruleOptions)
expect(messages.length).toBe(1)
expect(messages[0].rule.id).toBe(ruleId)
expect(messages[0].line).toBe(1)
expect(messages[0].col).toBe(12)
expect(messages.length).toBe(0)
})

it('Normal text should not result in an error', () => {
Expand Down

0 comments on commit 5b28af4

Please sign in to comment.