Problem with form action attribute-allowed-values (and tests)
The attribute-allowed-values
rule rejects valid values for <form action="...">
attribute. I think the fix should be simple (see below) but there is an added problem of current tests passing that shouldn't be passing.
Reduced test-case
To reproduce, edit file html-validate/test-files/elements/form-valid.html
and duplicate line 18 so you end up with:
...
<!-- should allow action attribute -->
<form action="/target"></form>
<form action="/target"></form>
...
Then running npm test -- -i elements/html5.spec.ts
will fail (on the original line 18).
Configuration
A fresh git clone / npm test of html-validate.
Expected result
Test to pass because "/target"
is a valid value.
Actual result
Test fails with error Attribute "action" has invalid value "/target"
.
Suggested fix (to primary issue)
I didn't dig into why the test originally passes when it shouldn't, but for the actual problem with the rule I played around a little. From looking (quickly) at Validator.validateAttributeValue
and the rules, I'm guessing the problem is that the rule definition (in elements/html5.js
line 534) is currently specifying the regular expression as a string instead of a RegExp. Changing the regular expression value from "\\s*\\S+\\s*"
to /\s*\S+\s*/
seems to fix the issue, but with side-effects of making tests from html-validate/test-files/elements/form-invalid.html
fail (that should pass).
Version
-
html-validate
: 7.3.1