Repository: htmlhint/HTMLHint

Issue:
spec-char-escape and &
**Describe the bug**

Ampersand is acceptable in HTML text

**To Reproduce**

HTMLHint generates an error:
> Special characters must be escaped : [  &  ]. (spec-char-escape)

[W3C Markup Validation Service](https://validator.w3.org/#validate_by_input) no longer finds any issues with the uncoded `&`.

```html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Title & More</title>
  </head>
  <body>
    <p>Drag & Drop</p>
  </body>
</html>
```

**Expected behavior**

No error


**Desktop (please complete the following information):**

- OS: Ubuntu 23.10
- HTMLHint: 1.1.4
- VS Code: 1.84.2
- [HTMLHint VS Code extension](https://marketplace.visualstudio.com/items?itemName=HTMLHint.vscode-htmlhint)

Hints from issue comments:
@erosman: https://github.com/htmlhint/HTMLHint/blob/21022c653721451da2bab49da10ea0e226acf862/src/core/rules/spec-char-escape.ts#L9-L10

`( \& )` is the cause of this issue, as it looks for `space-&-space`.

Therefore, the following won't look for `&`

```js
      // TODO: improve use-cases for &
      const reSpecChar = /[<>]/g
```

Solution patch:
diff --git a/docs/user-guide/rules/spec-char-escape.md b/docs/user-guide/rules/spec-char-escape.md
index b946586..67ed84b 100644
--- a/docs/user-guide/rules/spec-char-escape.md
+++ b/docs/user-guide/rules/spec-char-escape.md
@@ -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:
diff --git a/src/core/rules/spec-char-escape.ts b/src/core/rules/spec-char-escape.ts
index de16016..c436af9 100644
--- a/src/core/rules/spec-char-escape.ts
+++ b/src/core/rules/spec-char-escape.ts
@@ -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))) {



Test patch:
diff --git a/test/rules/spec-char-escape.spec.js b/test/rules/spec-char-escape.spec.js
index b1f8835..cd8c5f6 100644
--- a/test/rules/spec-char-escape.spec.js
+++ b/test/rules/spec-char-escape.spec.js
@@ -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', () => {