Commit 35e601e2 authored by David Sveningsson's avatar David Sveningsson
Browse files

fix(dom): `DOMTokenList` (such as `classlist`) handles newlines and tabs

parent ac4fe6d2
Pipeline #243500909 passed with stages
in 11 minutes and 13 seconds
......@@ -23,6 +23,18 @@ describe("DOMTokenList", () => {
expect(Array.from(list)).toEqual(["foo", "bar", "baz"]);
});
it("should handle newlines", () => {
expect.assertions(1);
const list = new DOMTokenList("foo\nbar\r\nbaz", location);
expect(Array.from(list)).toEqual(["foo", "bar", "baz"]);
});
it("should handle tabs", () => {
expect.assertions(1);
const list = new DOMTokenList("foo\tbar", location);
expect(Array.from(list)).toEqual(["foo", "bar"]);
});
it("should handle leading and trailing spaces", () => {
expect.assertions(1);
const list = new DOMTokenList(" foo bar baz ", location);
......
......@@ -47,7 +47,9 @@ export class DOMTokenList extends Array<string> {
public constructor(value: string | DynamicValue | null, location: Location | null) {
if (value && typeof value === "string") {
const { tokens, locations } = parse(value, location);
/* replace all whitespace with a single space for easier parsing */
const condensed = value.replace(/[\t\r\n ]+/g, " ");
const { tokens, locations } = parse(condensed, location);
super(...tokens);
this.locations = locations;
} else {
......
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