From 707d2b27979163d5493054fe54919fed5f9447e4 Mon Sep 17 00:00:00 2001 From: Dennis Snell Date: Fri, 9 Nov 2018 13:33:19 -0500 Subject: [PATCH] Parser: Allow empty attributes in default parsers Since the introduction of the default parser in #8083 we have had a subtle bug in the parsing which failed when empty attributes were specified in a block's comment delimiter - `{}` The absense of attributes was fine but _empty_ attributes were a failure. This is due to using `+?` in the RegExp tokenizer instead of using `*?` (which allows for no inner content in the JSON string). This patch updates the quantifier to restore functionality and fix the bug. This didn't appear in practice because we don't intentionally set `{}` as the attributes - the serializer drops it altogther, and our tests didn't catch it for similar reasons. --- packages/block-serialization-default-parser/parser.php | 2 +- packages/block-serialization-default-parser/src/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/block-serialization-default-parser/parser.php b/packages/block-serialization-default-parser/parser.php index 2211cf0c19226..b873b37fd78a4 100644 --- a/packages/block-serialization-default-parser/parser.php +++ b/packages/block-serialization-default-parser/parser.php @@ -364,7 +364,7 @@ function next_token() { * match back in PHP to see which one it was. */ $has_match = preg_match( - '/).)+?}\s+)?(?\/)?-->/s', + '/).)*?}\s+)?(?\/)?-->/s', $this->document, $matches, PREG_OFFSET_CAPTURE, diff --git a/packages/block-serialization-default-parser/src/index.js b/packages/block-serialization-default-parser/src/index.js index 577284fc1e539..936c4a380969c 100644 --- a/packages/block-serialization-default-parser/src/index.js +++ b/packages/block-serialization-default-parser/src/index.js @@ -2,7 +2,7 @@ let document; let offset; let output; let stack; -const tokenizer = /)[^])+?}\s+)?(\/)?-->/g; +const tokenizer = /)[^])*?}\s+)?(\/)?-->/g; function Block( blockName, attrs, innerBlocks, innerHTML, innerContent ) { return {