From c9e3762638c0cd858b72cbb096b8b228c2e26b8e Mon Sep 17 00:00:00 2001 From: Thomas Ghysels Date: Sun, 23 Jun 2019 14:41:56 +0200 Subject: [PATCH] Fix parsing ambiguous HTML entities (#3071) Fixes sveltejs/sapper#759 --- src/compiler/parse/utils/html.ts | 2 +- test/parser/samples/attribute-escaped/input.svelte | 2 +- test/parser/samples/attribute-escaped/output.json | 12 ++++++------ test/runtime/samples/html-entities/_config.js | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/compiler/parse/utils/html.ts b/src/compiler/parse/utils/html.ts index b49989eacd..13ff553a3f 100644 --- a/src/compiler/parse/utils/html.ts +++ b/src/compiler/parse/utils/html.ts @@ -36,7 +36,7 @@ const windows_1252 = [ ]; const entity_pattern = new RegExp( - `&(#?(?:x[\\w\\d]+|\\d+|${Object.keys(entities).join('|')}));?`, + `&(#?(?:x[\\w\\d]+|\\d+|${Object.keys(entities).join('|')}))(?:;|\\b)`, 'g' ); diff --git a/test/parser/samples/attribute-escaped/input.svelte b/test/parser/samples/attribute-escaped/input.svelte index 82186dcee4..4c9cd5ff68 100644 --- a/test/parser/samples/attribute-escaped/input.svelte +++ b/test/parser/samples/attribute-escaped/input.svelte @@ -1 +1 @@ -
+
diff --git a/test/parser/samples/attribute-escaped/output.json b/test/parser/samples/attribute-escaped/output.json index e60a8c2531..a8498bd574 100644 --- a/test/parser/samples/attribute-escaped/output.json +++ b/test/parser/samples/attribute-escaped/output.json @@ -1,27 +1,27 @@ { "html": { "start": 0, - "end": 41, + "end": 83, "type": "Fragment", "children": [ { "start": 0, - "end": 41, + "end": 83, "type": "Element", "name": "div", "attributes": [ { "start": 5, - "end": 34, + "end": 76, "type": "Attribute", "name": "data-foo", "value": [ { "start": 15, - "end": 33, + "end": 75, "type": "Text", - "raw": ""quoted"", - "data": "\"quoted\"" + "raw": "semi:"space:" letter:"e number:"1 end:"", + "data": "semi:\"space:\" letter:"e number:"1 end:\"" } ] } diff --git a/test/runtime/samples/html-entities/_config.js b/test/runtime/samples/html-entities/_config.js index 1591f31a53..c8c2de8403 100644 --- a/test/runtime/samples/html-entities/_config.js +++ b/test/runtime/samples/html-entities/_config.js @@ -9,6 +9,6 @@ export default { A - ¬anentity; + &notanentity; ` }; \ No newline at end of file