Commit 94ce2a85 authored by David Sveningsson's avatar David Sveningsson

fix(rules): fix prefer-button crashing on boolean type attribute

parent cee2bbd0
Pipeline #82302695 passed with stages
in 7 minutes and 14 seconds
......@@ -10,6 +10,16 @@ describe("rule prefer-button", () => {
});
});
it("should not report error when type attribute is missing type attribute", () => {
const report = htmlvalidate.validateString("<input>");
expect(report).toBeValid();
});
it("should not report error when type attribute is missing value", () => {
const report = htmlvalidate.validateString("<input type>");
expect(report).toBeValid();
});
it("should not report error when using regular input fields", () => {
const report = htmlvalidate.validateString('<input type="text">');
expect(report).toBeValid();
......
......@@ -19,7 +19,13 @@ class PreferButton extends Rule {
}
const type = node.getAttribute("type");
if (type && type.valueMatches(/^(button|submit|reset|image)$/, false)) {
/* sanity check: handle missing and boolean attributes */
if (!type || type.value === null) {
return;
}
if (type.valueMatches(/^(button|submit|reset|image)$/, false)) {
this.report(
node,
`Prefer to use <button> instead of <input type="${type.value}"> when adding buttons`,
......
Markdown is supported
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