From c52a6f011b383532feb91304d2c6bc38e1e20254 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Fri, 24 Aug 2018 08:22:41 -0400 Subject: [PATCH] dont warn on empty block for nbsp - fixes #1658 --- src/validate/html/index.ts | 2 +- test/validator/samples/non-empty-block-dev/_config.js | 3 +++ test/validator/samples/non-empty-block-dev/input.html | 3 +++ test/validator/samples/non-empty-block-dev/warnings.json | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test/validator/samples/non-empty-block-dev/_config.js create mode 100644 test/validator/samples/non-empty-block-dev/input.html create mode 100644 test/validator/samples/non-empty-block-dev/warnings.json diff --git a/src/validate/html/index.ts b/src/validate/html/index.ts index ed4eaf4d38..eabe9d8872 100644 --- a/src/validate/html/index.ts +++ b/src/validate/html/index.ts @@ -14,7 +14,7 @@ function isEmptyBlock(node: Node) { if (!/Block$/.test(node.type) || !node.children) return false; if (node.children.length > 1) return false; const child = node.children[0]; - return !child || (child.type === 'Text' && !/\S/.test(child.data)); + return !child || (child.type === 'Text' && !/[^ \r\n\f\v\t]/.test(child.data)); } export default function validateHtml(validator: Validator, html: Node) { diff --git a/test/validator/samples/non-empty-block-dev/_config.js b/test/validator/samples/non-empty-block-dev/_config.js new file mode 100644 index 0000000000..e26996239d --- /dev/null +++ b/test/validator/samples/non-empty-block-dev/_config.js @@ -0,0 +1,3 @@ +export default { + dev: true +}; \ No newline at end of file diff --git a/test/validator/samples/non-empty-block-dev/input.html b/test/validator/samples/non-empty-block-dev/input.html new file mode 100644 index 0000000000..ed4b9e6274 --- /dev/null +++ b/test/validator/samples/non-empty-block-dev/input.html @@ -0,0 +1,3 @@ +{#if x} +   +{/if} \ No newline at end of file diff --git a/test/validator/samples/non-empty-block-dev/warnings.json b/test/validator/samples/non-empty-block-dev/warnings.json new file mode 100644 index 0000000000..0637a088a0 --- /dev/null +++ b/test/validator/samples/non-empty-block-dev/warnings.json @@ -0,0 +1 @@ +[] \ No newline at end of file