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

fix: handle directives with excessive whitespace

parent a10dc638
Pipeline #291514025 passed with stages
in 10 minutes and 35 seconds
......@@ -706,17 +706,59 @@ describe("lexer", () => {
expect(token.next().done).toBeTruthy();
});
it("html-validate directive", () => {
expect.assertions(3);
const token = lexer.tokenize(
inlineSource("<!-- [html-validate-action options: comment] -->")
);
expect(token.next()).toBeToken({
type: TokenType.DIRECTIVE,
data: ["<!-- [html-validate-action options: comment] -->", "action options: comment"],
describe("html-validate directive", () => {
it("with comment", () => {
expect.assertions(3);
const token = lexer.tokenize(
inlineSource("<!-- [html-validate-action options: comment] -->")
);
expect(token.next()).toBeToken({
type: TokenType.DIRECTIVE,
data: ["<!-- [html-validate-action options: comment] -->", "action options: comment"],
});
expect(token.next()).toBeToken({ type: TokenType.EOF });
expect(token.next().done).toBeTruthy();
});
it("without comment", () => {
expect.assertions(3);
const token = lexer.tokenize(inlineSource("<!-- [html-validate-action options] -->"));
expect(token.next()).toBeToken({
type: TokenType.DIRECTIVE,
data: ["<!-- [html-validate-action options] -->", "action options"],
});
expect(token.next()).toBeToken({ type: TokenType.EOF });
expect(token.next().done).toBeTruthy();
});
it("with excessive whitespace", () => {
expect.assertions(3);
const token = lexer.tokenize(
inlineSource("<!-- \t\n\t [html-validate-action options: comment] \t\n\t -->")
);
expect(token.next()).toBeToken({
type: TokenType.DIRECTIVE,
data: [
"<!-- \t\n\t [html-validate-action options: comment] \t\n\t -->",
"action options: comment",
],
});
expect(token.next()).toBeToken({ type: TokenType.EOF });
expect(token.next().done).toBeTruthy();
});
it("with no whitespace", () => {
expect.assertions(3);
const token = lexer.tokenize(
inlineSource("<!--[html-validate-action options: comment]-->")
);
expect(token.next()).toBeToken({
type: TokenType.DIRECTIVE,
data: ["<!--[html-validate-action options: comment]-->", "action options: comment"],
});
expect(token.next()).toBeToken({ type: TokenType.EOF });
expect(token.next().done).toBeTruthy();
});
expect(token.next()).toBeToken({ type: TokenType.EOF });
expect(token.next().done).toBeTruthy();
});
/* downlevel reveal is a non-standard "tag", handled separately */
......
......@@ -25,7 +25,7 @@ const MATCH_CDATA_BEGIN = /^<!\[CDATA\[/;
const MATCH_CDATA_END = /^[^]*?]]>/;
const MATCH_SCRIPT_DATA = /^[^]*?(?=<\/script)/;
const MATCH_SCRIPT_END = /^<(\/)(script)/;
const MATCH_DIRECTIVE = /^<!--\s\[html-validate-(.*?)]\s-->/;
const MATCH_DIRECTIVE = /^<!--\s*\[html-validate-(.*?)]\s*-->/;
const MATCH_COMMENT = /^<!--([^]*?)-->/;
const MATCH_CONDITIONAL = /^<!\[([^\]]*?)\]>/;
......
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