Commit 2e46586b authored by Stefan Kalscheuer's avatar Stefan Kalscheuer
Browse files

fix: only check value of type attribute in prefer-button rule

The prefer-button rule should detect <input> elements of button-like
types. Searching all attribute values for these types, e.g. "submit",
yields false positives if this string in other places.

We now only check the value of the "type" attribute to prevent false
positives with this rule.
parent fd4fc63b
......@@ -80,6 +80,14 @@ describe("rule prefer-button", () => {
);
});
it("should not report error when using submit keyword in other attributes", () => {
expect.assertions(1);
const report = htmlvalidate.validateString(
'<input type="hidden" name="action" value="submit">'
);
expect(report).toBeValid();
});
it("smoketest", () => {
expect.assertions(1);
const report = htmlvalidate.validateFile("test-files/rules/prefer-button.html");
......
......@@ -82,6 +82,11 @@ export default class PreferButton extends Rule<RuleContext, RuleOptions> {
return;
}
/* only handle type attribute */
if (event.key !== "type") {
return;
}
/* sanity check: handle missing, boolean and dynamic attributes */
if (!event.value || event.value instanceof DynamicValue) {
return;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment