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

fix: handle multiline templating strings

fixes #134
parent 9dda762c
Pipeline #381102083 passed with stages
in 12 minutes and 13 seconds
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`regression tests test-files/issues/issue-134-multiline-template.html 1`] = `Array []`;
exports[`regression tests test-files/issues/issue27-disable-block.html 1`] = `Array []`;
exports[`regression tests test-files/issues/issue35-dynamic-values.html 1`] = `Array []`;
......
......@@ -786,11 +786,14 @@ describe("lexer", () => {
describe("should not choke on templating", () => {
it.each`
input
${"<% ... %>"}
${"<? ... ?>"}
${"<$ ... $>"}
`("$input", ({ input }) => {
input | description
${"<% ... %>"} | ${"<% ... %>"}
${"<%\n...\n%>"} | ${"<% ... %> (with newlines)"}
${"<? ... ?>"} | ${"<? ... ?>"}
${"<?\n...\n?>"} | ${"<? ... ?> (with newlines)"}
${"<$ ... $>"} | ${"<$ ... $>"}
${"<$\n...\n$>"} | ${"<$ ... $> (with newlines)"}
`("$description", ({ input }) => {
const token = lexer.tokenize(inlineSource(input));
expect(token.next()).toBeToken({
type: TokenType.TEMPLATING,
......
......@@ -15,7 +15,7 @@ const MATCH_XML_TAG = /^<\?xml.*?\?>\s+/;
const MATCH_TAG_OPEN = /^<(\/?)([a-zA-Z0-9\-:]+)/; // https://www.w3.org/TR/html/syntax.html#start-tags
const MATCH_TAG_CLOSE = /^\/?>/;
const MATCH_TEXT = /^[^]*?(?=(?:[ \t]*(?:\r\n|\r|\n)|<[^ ]|$))/;
const MATCH_TEMPLATING = /^(?:<%.*?%>|<\?.*?\?>|<\$.*?\$>)/;
const MATCH_TEMPLATING = /^(?:<%.*?%>|<\?.*?\?>|<\$.*?\$>)/s;
const MATCH_TAG_LOOKAHEAD = /^[^]*?(?=<|$)/;
const MATCH_ATTR_START = /^([^\t\r\n\f \/><"'=]+)/; // https://www.w3.org/TR/html/syntax.html#elements-attributes
const MATCH_ATTR_SINGLE = /^(\s*=\s*)'([^']*?)(')/;
......
......@@ -132,11 +132,14 @@ describe("rule no-raw-characters", () => {
describe("should not report templating", () => {
it.each`
input
${"<% ... %>"}
${"<? ... ?>"}
${"<$ ... $>"}
`("$input", ({ input }) => {
input | description
${"<% & %>"} | ${"<% & %>"}
${"<%\n&\n%>"} | ${"<% & %> (with newlines)"}
${"<? & ?>"} | ${"<? & ?>"}
${"<?\n&\n?>"} | ${"<? & ?> (with newlines)"}
${"<$ & $>"} | ${"<$ & $>"}
${"<$\n&\n$>"} | ${"<$ & $> (with newlines)"}
`("$description", ({ input }) => {
expect.assertions(1);
const report = htmlvalidate.validateString(`<p>lorem ${input} ipsum</p>`);
expect(report).toBeValid();
......
......@@ -13,7 +13,7 @@ const defaults: RuleOptions = {
const textRegexp = /([<>]|&(?![a-zA-Z0-9#]+;))/g;
const unquotedAttrRegexp = /([<>"'=`]|&(?![a-zA-Z0-9#]+;))/g;
const matchTemplate = /^(<%.*?%>|<\?.*?\?>|<\$.*?\$>)$/;
const matchTemplate = /^(<%.*?%>|<\?.*?\?>|<\$.*?\$>)$/s;
const replacementTable: Map<string, string> = new Map([
['"', "&quot;"],
......
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