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

fix(spec-char-escape): remove normal ampersand from spec-char-escape … #1411

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
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
Loading