Skip to content

Commit

Permalink
fix(spec-char-escape): remove normal ampersand from spec-char-escape …
Browse files Browse the repository at this point in the history
…rule, update test and docs

Ampersand is acceptable in HTML text. W3C Markup Validation Service no longer finds any issues with
the uncoded &.

fix htmlhint#1382
  • Loading branch information
bebehr committed Feb 18, 2024
1 parent 35aecf5 commit 9d5a70f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 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
2 changes: 1 addition & 1 deletion src/core/rules/spec-char-escape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
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 9d5a70f

Please sign in to comment.