Commit a71b9474 authored by David Sveningsson's avatar David Sveningsson
Browse files

fix: handle leading and trailing whitespace in `style` attributes

fixes #122
parent b32412e3
Pipeline #328496804 passed with stages
in 9 minutes and 50 seconds
......@@ -34,6 +34,27 @@ describe("rule no-inline-style", () => {
expect(report).toBeInvalid();
expect(report).toHaveError("no-inline-style", "Inline style is not allowed");
});
it("should handle leading whitespace", () => {
expect.assertions(2);
const report = htmlvalidate.validateString('<p style=" color: red"></p>');
expect(report).toBeInvalid();
expect(report).toHaveError("no-inline-style", "Inline style is not allowed");
});
it("should handle trailing whitespace", () => {
expect.assertions(2);
const report = htmlvalidate.validateString('<p style="color: red; "></p>');
expect(report).toBeInvalid();
expect(report).toHaveError("no-inline-style", "Inline style is not allowed");
});
it("should handle only whitespace", () => {
expect.assertions(2);
const report = htmlvalidate.validateString('<p style=" "></p>');
expect(report).toBeInvalid();
expect(report).toHaveError("no-inline-style", "Inline style is not allowed");
});
});
describe("configured with include", () => {
......
......@@ -21,6 +21,7 @@ const defaults: RuleOptions = {
function getCSSDeclarations(value: string): CSSDeclaration[] {
return value
.trim()
.split(";")
.filter(Boolean)
.map((it): CSSDeclaration => {
......
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