htmlhint / HTMLHint

⚙️ The static code analysis tool you need for your HTML
https://htmlhint.com
MIT License
3.07k stars 375 forks source link

spec-char-escape and & #1382

Open erosman opened 8 months ago

erosman commented 8 months ago

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 no longer finds any issues with the uncoded &.

<!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):

erosman commented 7 months ago

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 &

      // TODO: improve use-cases for &
      const reSpecChar = /[<>]/g