diff --git a/lib/parser.php b/lib/parser.php index 330249196861a0..e73abf2bc16498 100644 --- a/lib/parser.php +++ b/lib/parser.php @@ -1121,155 +1121,193 @@ private function peg_parseBlock_Attributes() { } } if ($s3 !== $this->peg_FAILED) { - $s4 = array(); - $s5 = $this->peg_currPos; + $s4 = $this->peg_currPos; + $s5 = array(); $s6 = $this->peg_currPos; - $this->peg_silentFails++; $s7 = $this->peg_currPos; + $s8 = array(); + $s9 = $this->peg_currPos; + $s10 = $this->peg_currPos; + $this->peg_silentFails++; if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c20) { - $s8 = $this->peg_c20; + $s11 = $this->peg_c20; $this->peg_currPos++; } else { - $s8 = $this->peg_FAILED; + $s11 = $this->peg_FAILED; if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c21); } } - if ($s8 !== $this->peg_FAILED) { - $s9 = $this->peg_parse__(); - if ($s9 !== $this->peg_FAILED) { - $s10 = $this->peg_c22; + $this->peg_silentFails--; + if ($s11 === $this->peg_FAILED) { + $s10 = null; + } else { + $this->peg_currPos = $s10; + $s10 = $this->peg_FAILED; + } + if ($s10 !== $this->peg_FAILED) { + if ($this->input_length > $this->peg_currPos) { + $s11 = $this->input_substr($this->peg_currPos, 1); + $this->peg_currPos++; + } else { + $s11 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { + $this->peg_fail($this->peg_c0); + } + } + if ($s11 !== $this->peg_FAILED) { + $s10 = array($s10, $s11); + $s9 = $s10; + } else { + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + if ($s9 !== $this->peg_FAILED) { + while ($s9 !== $this->peg_FAILED) { + $s8[] = $s9; + $s9 = $this->peg_currPos; + $s10 = $this->peg_currPos; + $this->peg_silentFails++; + if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c20) { + $s11 = $this->peg_c20; + $this->peg_currPos++; + } else { + $s11 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { + $this->peg_fail($this->peg_c21); + } + } + $this->peg_silentFails--; + if ($s11 === $this->peg_FAILED) { + $s10 = null; + } else { + $this->peg_currPos = $s10; + $s10 = $this->peg_FAILED; + } if ($s10 !== $this->peg_FAILED) { - if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c11) { - $s11 = $this->peg_c11; + if ($this->input_length > $this->peg_currPos) { + $s11 = $this->input_substr($this->peg_currPos, 1); $this->peg_currPos++; } else { $s11 = $this->peg_FAILED; if ($this->peg_silentFails === 0) { - $this->peg_fail($this->peg_c12); + $this->peg_fail($this->peg_c0); } } - if ($s11 === $this->peg_FAILED) { - $s11 = null; - } if ($s11 !== $this->peg_FAILED) { - if ($this->input_substr($this->peg_currPos, 3) === $this->peg_c7) { - $s12 = $this->peg_c7; - $this->peg_currPos += 3; - } else { - $s12 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { - $this->peg_fail($this->peg_c8); - } - } - if ($s12 !== $this->peg_FAILED) { - $s8 = array($s8, $s9, $s10, $s11, $s12); - $s7 = $s8; - } else { - $this->peg_currPos = $s7; - $s7 = $this->peg_FAILED; - } + $s10 = array($s10, $s11); + $s9 = $s10; } else { - $this->peg_currPos = $s7; - $s7 = $this->peg_FAILED; + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; } } else { - $this->peg_currPos = $s7; - $s7 = $this->peg_FAILED; + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; } - } else { - $this->peg_currPos = $s7; - $s7 = $this->peg_FAILED; } } else { - $this->peg_currPos = $s7; - $s7 = $this->peg_FAILED; + $s8 = $this->peg_FAILED; } - $this->peg_silentFails--; - if ($s7 === $this->peg_FAILED) { - $s6 = null; + if ($s8 !== $this->peg_FAILED) { + $s7 = $this->input_substr($s7, $this->peg_currPos - $s7); } else { - $this->peg_currPos = $s6; - $s6 = $this->peg_FAILED; + $s7 = $s8; } - if ($s6 !== $this->peg_FAILED) { - if ($this->input_length > $this->peg_currPos) { - $s7 = $this->input_substr($this->peg_currPos, 1); - $this->peg_currPos++; - } else { - $s7 = $this->peg_FAILED; - if ($this->peg_silentFails === 0) { - $this->peg_fail($this->peg_c0); - } - } - if ($s7 !== $this->peg_FAILED) { - $s6 = array($s6, $s7); - $s5 = $s6; - } else { - $this->peg_currPos = $s5; - $s5 = $this->peg_FAILED; - } + if ($s7 !== $this->peg_FAILED) { + $s6 = $this->input_substr($s6, $this->peg_currPos - $s6); } else { - $this->peg_currPos = $s5; - $s5 = $this->peg_FAILED; + $s6 = $s7; } - while ($s5 !== $this->peg_FAILED) { - $s4[] = $s5; - $s5 = $this->peg_currPos; + if ($s6 === $this->peg_FAILED) { $s6 = $this->peg_currPos; - $this->peg_silentFails++; $s7 = $this->peg_currPos; + $s8 = $this->peg_currPos; + $this->peg_silentFails++; + $s9 = $this->peg_currPos; if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c20) { - $s8 = $this->peg_c20; + $s10 = $this->peg_c20; $this->peg_currPos++; } else { - $s8 = $this->peg_FAILED; + $s10 = $this->peg_FAILED; if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c21); } } - if ($s8 !== $this->peg_FAILED) { - $s9 = $this->peg_parse__(); - if ($s9 !== $this->peg_FAILED) { - $s10 = $this->peg_c22; - if ($s10 !== $this->peg_FAILED) { + if ($s10 !== $this->peg_FAILED) { + $s11 = $this->peg_parse__(); + if ($s11 !== $this->peg_FAILED) { + $s12 = $this->peg_c22; + if ($s12 !== $this->peg_FAILED) { if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c11) { - $s11 = $this->peg_c11; + $s13 = $this->peg_c11; $this->peg_currPos++; } else { - $s11 = $this->peg_FAILED; + $s13 = $this->peg_FAILED; if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c12); } } - if ($s11 === $this->peg_FAILED) { - $s11 = null; + if ($s13 === $this->peg_FAILED) { + $s13 = null; } - if ($s11 !== $this->peg_FAILED) { + if ($s13 !== $this->peg_FAILED) { if ($this->input_substr($this->peg_currPos, 3) === $this->peg_c7) { - $s12 = $this->peg_c7; + $s14 = $this->peg_c7; $this->peg_currPos += 3; } else { - $s12 = $this->peg_FAILED; + $s14 = $this->peg_FAILED; if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c8); } } - if ($s12 !== $this->peg_FAILED) { - $s8 = array($s8, $s9, $s10, $s11, $s12); - $s7 = $s8; + if ($s14 !== $this->peg_FAILED) { + $s10 = array($s10, $s11, $s12, $s13, $s14); + $s9 = $s10; } else { - $this->peg_currPos = $s7; - $s7 = $this->peg_FAILED; + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; } } else { - $this->peg_currPos = $s7; - $s7 = $this->peg_FAILED; + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; } } else { - $this->peg_currPos = $s7; - $s7 = $this->peg_FAILED; + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + $this->peg_silentFails--; + if ($s9 === $this->peg_FAILED) { + $s8 = null; + } else { + $this->peg_currPos = $s8; + $s8 = $this->peg_FAILED; + } + if ($s8 !== $this->peg_FAILED) { + if ($this->input_length > $this->peg_currPos) { + $s9 = $this->input_substr($this->peg_currPos, 1); + $this->peg_currPos++; + } else { + $s9 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { + $this->peg_fail($this->peg_c0); } + } + if ($s9 !== $this->peg_FAILED) { + $s8 = array($s8, $s9); + $s7 = $s8; } else { $this->peg_currPos = $s7; $s7 = $this->peg_FAILED; @@ -1278,35 +1316,219 @@ private function peg_parseBlock_Attributes() { $this->peg_currPos = $s7; $s7 = $this->peg_FAILED; } + if ($s7 !== $this->peg_FAILED) { + $s6 = $this->input_substr($s6, $this->peg_currPos - $s6); + } else { + $s6 = $s7; + } + } + while ($s6 !== $this->peg_FAILED) { + $s5[] = $s6; + $s6 = $this->peg_currPos; + $s7 = $this->peg_currPos; + $s8 = array(); + $s9 = $this->peg_currPos; + $s10 = $this->peg_currPos; + $this->peg_silentFails++; + if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c20) { + $s11 = $this->peg_c20; + $this->peg_currPos++; + } else { + $s11 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { + $this->peg_fail($this->peg_c21); + } + } $this->peg_silentFails--; - if ($s7 === $this->peg_FAILED) { - $s6 = null; + if ($s11 === $this->peg_FAILED) { + $s10 = null; } else { - $this->peg_currPos = $s6; - $s6 = $this->peg_FAILED; + $this->peg_currPos = $s10; + $s10 = $this->peg_FAILED; } - if ($s6 !== $this->peg_FAILED) { + if ($s10 !== $this->peg_FAILED) { if ($this->input_length > $this->peg_currPos) { - $s7 = $this->input_substr($this->peg_currPos, 1); + $s11 = $this->input_substr($this->peg_currPos, 1); $this->peg_currPos++; } else { - $s7 = $this->peg_FAILED; + $s11 = $this->peg_FAILED; if ($this->peg_silentFails === 0) { $this->peg_fail($this->peg_c0); } } - if ($s7 !== $this->peg_FAILED) { - $s6 = array($s6, $s7); - $s5 = $s6; + if ($s11 !== $this->peg_FAILED) { + $s10 = array($s10, $s11); + $s9 = $s10; } else { - $this->peg_currPos = $s5; - $s5 = $this->peg_FAILED; + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; } } else { - $this->peg_currPos = $s5; - $s5 = $this->peg_FAILED; + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + if ($s9 !== $this->peg_FAILED) { + while ($s9 !== $this->peg_FAILED) { + $s8[] = $s9; + $s9 = $this->peg_currPos; + $s10 = $this->peg_currPos; + $this->peg_silentFails++; + if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c20) { + $s11 = $this->peg_c20; + $this->peg_currPos++; + } else { + $s11 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { + $this->peg_fail($this->peg_c21); + } + } + $this->peg_silentFails--; + if ($s11 === $this->peg_FAILED) { + $s10 = null; + } else { + $this->peg_currPos = $s10; + $s10 = $this->peg_FAILED; + } + if ($s10 !== $this->peg_FAILED) { + if ($this->input_length > $this->peg_currPos) { + $s11 = $this->input_substr($this->peg_currPos, 1); + $this->peg_currPos++; + } else { + $s11 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { + $this->peg_fail($this->peg_c0); + } + } + if ($s11 !== $this->peg_FAILED) { + $s10 = array($s10, $s11); + $s9 = $s10; + } else { + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + } + } else { + $s8 = $this->peg_FAILED; + } + if ($s8 !== $this->peg_FAILED) { + $s7 = $this->input_substr($s7, $this->peg_currPos - $s7); + } else { + $s7 = $s8; + } + if ($s7 !== $this->peg_FAILED) { + $s6 = $this->input_substr($s6, $this->peg_currPos - $s6); + } else { + $s6 = $s7; + } + if ($s6 === $this->peg_FAILED) { + $s6 = $this->peg_currPos; + $s7 = $this->peg_currPos; + $s8 = $this->peg_currPos; + $this->peg_silentFails++; + $s9 = $this->peg_currPos; + if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c20) { + $s10 = $this->peg_c20; + $this->peg_currPos++; + } else { + $s10 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { + $this->peg_fail($this->peg_c21); + } + } + if ($s10 !== $this->peg_FAILED) { + $s11 = $this->peg_parse__(); + if ($s11 !== $this->peg_FAILED) { + $s12 = $this->peg_c22; + if ($s12 !== $this->peg_FAILED) { + if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c11) { + $s13 = $this->peg_c11; + $this->peg_currPos++; + } else { + $s13 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { + $this->peg_fail($this->peg_c12); + } + } + if ($s13 === $this->peg_FAILED) { + $s13 = null; + } + if ($s13 !== $this->peg_FAILED) { + if ($this->input_substr($this->peg_currPos, 3) === $this->peg_c7) { + $s14 = $this->peg_c7; + $this->peg_currPos += 3; + } else { + $s14 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { + $this->peg_fail($this->peg_c8); + } + } + if ($s14 !== $this->peg_FAILED) { + $s10 = array($s10, $s11, $s12, $s13, $s14); + $s9 = $s10; + } else { + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s9; + $s9 = $this->peg_FAILED; + } + $this->peg_silentFails--; + if ($s9 === $this->peg_FAILED) { + $s8 = null; + } else { + $this->peg_currPos = $s8; + $s8 = $this->peg_FAILED; + } + if ($s8 !== $this->peg_FAILED) { + if ($this->input_length > $this->peg_currPos) { + $s9 = $this->input_substr($this->peg_currPos, 1); + $this->peg_currPos++; + } else { + $s9 = $this->peg_FAILED; + if ($this->peg_silentFails === 0) { + $this->peg_fail($this->peg_c0); + } + } + if ($s9 !== $this->peg_FAILED) { + $s8 = array($s8, $s9); + $s7 = $s8; + } else { + $this->peg_currPos = $s7; + $s7 = $this->peg_FAILED; + } + } else { + $this->peg_currPos = $s7; + $s7 = $this->peg_FAILED; + } + if ($s7 !== $this->peg_FAILED) { + $s6 = $this->input_substr($s6, $this->peg_currPos - $s6); + } else { + $s6 = $s7; + } } } + if ($s5 !== $this->peg_FAILED) { + $s4 = $this->input_substr($s4, $this->peg_currPos - $s4); + } else { + $s4 = $s5; + } if ($s4 !== $this->peg_FAILED) { if ($this->input_substr($this->peg_currPos, 1) === $this->peg_c20) { $s5 = $this->peg_c20; diff --git a/packages/block-serialization-default-parser/parser.php b/packages/block-serialization-default-parser/parser.php index 78b6921787cc48..9eb8aae492b723 100644 --- a/packages/block-serialization-default-parser/parser.php +++ b/packages/block-serialization-default-parser/parser.php @@ -347,7 +347,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 77306b0e347c7b..27dd93bb9fb0f1 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 ) { return { diff --git a/packages/block-serialization-spec-parser/grammar.pegjs b/packages/block-serialization-spec-parser/grammar.pegjs index 00d1fec2114136..85df9eba024ce6 100644 --- a/packages/block-serialization-spec-parser/grammar.pegjs +++ b/packages/block-serialization-spec-parser/grammar.pegjs @@ -290,7 +290,7 @@ Block_Name_Part Block_Attributes "JSON-encoded attributes embedded in a block's opening comment" - = attrs:$("{" (!("}" __ """/"? "-->") .)* "}") + = attrs:$("{" ( (!"}" .)+ / (!("}" __ """/"? "-->") .) )* "}") { /** **/ return maybeJSON( attrs ); diff --git a/packages/block-serialization-spec-parser/parser.js b/packages/block-serialization-spec-parser/parser.js index e716efb9e3e8d2..220cf6dd530f8f 100644 --- a/packages/block-serialization-spec-parser/parser.js +++ b/packages/block-serialization-spec-parser/parser.js @@ -1170,7 +1170,7 @@ } function peg$parseBlock_Attributes() { - var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12; + var s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14; peg$silentFails++; s0 = peg$currPos; @@ -1184,141 +1184,177 @@ if (peg$silentFails === 0) { peg$fail(peg$c27); } } if (s3 !== peg$FAILED) { - s4 = []; - s5 = peg$currPos; + s4 = peg$currPos; + s5 = []; s6 = peg$currPos; - peg$silentFails++; s7 = peg$currPos; + s8 = []; + s9 = peg$currPos; + s10 = peg$currPos; + peg$silentFails++; if (input.charCodeAt(peg$currPos) === 125) { - s8 = peg$c28; + s11 = peg$c28; peg$currPos++; } else { - s8 = peg$FAILED; + s11 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c29); } } - if (s8 !== peg$FAILED) { - s9 = peg$parse__(); - if (s9 !== peg$FAILED) { - s10 = peg$c30; + peg$silentFails--; + if (s11 === peg$FAILED) { + s10 = void 0; + } else { + peg$currPos = s10; + s10 = peg$FAILED; + } + if (s10 !== peg$FAILED) { + if (input.length > peg$currPos) { + s11 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s11 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c0); } + } + if (s11 !== peg$FAILED) { + s10 = [s10, s11]; + s9 = s10; + } else { + peg$currPos = s9; + s9 = peg$FAILED; + } + } else { + peg$currPos = s9; + s9 = peg$FAILED; + } + if (s9 !== peg$FAILED) { + while (s9 !== peg$FAILED) { + s8.push(s9); + s9 = peg$currPos; + s10 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 125) { + s11 = peg$c28; + peg$currPos++; + } else { + s11 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c29); } + } + peg$silentFails--; + if (s11 === peg$FAILED) { + s10 = void 0; + } else { + peg$currPos = s10; + s10 = peg$FAILED; + } if (s10 !== peg$FAILED) { - if (input.charCodeAt(peg$currPos) === 47) { - s11 = peg$c18; + if (input.length > peg$currPos) { + s11 = input.charAt(peg$currPos); peg$currPos++; } else { s11 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c19); } - } - if (s11 === peg$FAILED) { - s11 = null; + if (peg$silentFails === 0) { peg$fail(peg$c0); } } if (s11 !== peg$FAILED) { - if (input.substr(peg$currPos, 3) === peg$c12) { - s12 = peg$c12; - peg$currPos += 3; - } else { - s12 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c13); } - } - if (s12 !== peg$FAILED) { - s8 = [s8, s9, s10, s11, s12]; - s7 = s8; - } else { - peg$currPos = s7; - s7 = peg$FAILED; - } + s10 = [s10, s11]; + s9 = s10; } else { - peg$currPos = s7; - s7 = peg$FAILED; + peg$currPos = s9; + s9 = peg$FAILED; } } else { - peg$currPos = s7; - s7 = peg$FAILED; + peg$currPos = s9; + s9 = peg$FAILED; } - } else { - peg$currPos = s7; - s7 = peg$FAILED; } } else { - peg$currPos = s7; - s7 = peg$FAILED; + s8 = peg$FAILED; } - peg$silentFails--; - if (s7 === peg$FAILED) { - s6 = void 0; + if (s8 !== peg$FAILED) { + s7 = input.substring(s7, peg$currPos); } else { - peg$currPos = s6; - s6 = peg$FAILED; + s7 = s8; } - if (s6 !== peg$FAILED) { - if (input.length > peg$currPos) { - s7 = input.charAt(peg$currPos); - peg$currPos++; - } else { - s7 = peg$FAILED; - if (peg$silentFails === 0) { peg$fail(peg$c0); } - } - if (s7 !== peg$FAILED) { - s6 = [s6, s7]; - s5 = s6; - } else { - peg$currPos = s5; - s5 = peg$FAILED; - } + if (s7 !== peg$FAILED) { + s6 = input.substring(s6, peg$currPos); } else { - peg$currPos = s5; - s5 = peg$FAILED; + s6 = s7; } - while (s5 !== peg$FAILED) { - s4.push(s5); - s5 = peg$currPos; + if (s6 === peg$FAILED) { s6 = peg$currPos; - peg$silentFails++; s7 = peg$currPos; + s8 = peg$currPos; + peg$silentFails++; + s9 = peg$currPos; if (input.charCodeAt(peg$currPos) === 125) { - s8 = peg$c28; + s10 = peg$c28; peg$currPos++; } else { - s8 = peg$FAILED; + s10 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c29); } } - if (s8 !== peg$FAILED) { - s9 = peg$parse__(); - if (s9 !== peg$FAILED) { - s10 = peg$c30; - if (s10 !== peg$FAILED) { + if (s10 !== peg$FAILED) { + s11 = peg$parse__(); + if (s11 !== peg$FAILED) { + s12 = peg$c30; + if (s12 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 47) { - s11 = peg$c18; + s13 = peg$c18; peg$currPos++; } else { - s11 = peg$FAILED; + s13 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c19); } } - if (s11 === peg$FAILED) { - s11 = null; + if (s13 === peg$FAILED) { + s13 = null; } - if (s11 !== peg$FAILED) { + if (s13 !== peg$FAILED) { if (input.substr(peg$currPos, 3) === peg$c12) { - s12 = peg$c12; + s14 = peg$c12; peg$currPos += 3; } else { - s12 = peg$FAILED; + s14 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c13); } } - if (s12 !== peg$FAILED) { - s8 = [s8, s9, s10, s11, s12]; - s7 = s8; + if (s14 !== peg$FAILED) { + s10 = [s10, s11, s12, s13, s14]; + s9 = s10; } else { - peg$currPos = s7; - s7 = peg$FAILED; + peg$currPos = s9; + s9 = peg$FAILED; } } else { - peg$currPos = s7; - s7 = peg$FAILED; + peg$currPos = s9; + s9 = peg$FAILED; } } else { - peg$currPos = s7; - s7 = peg$FAILED; + peg$currPos = s9; + s9 = peg$FAILED; } + } else { + peg$currPos = s9; + s9 = peg$FAILED; + } + } else { + peg$currPos = s9; + s9 = peg$FAILED; + } + peg$silentFails--; + if (s9 === peg$FAILED) { + s8 = void 0; + } else { + peg$currPos = s8; + s8 = peg$FAILED; + } + if (s8 !== peg$FAILED) { + if (input.length > peg$currPos) { + s9 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s9 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c0); } + } + if (s9 !== peg$FAILED) { + s8 = [s8, s9]; + s7 = s8; } else { peg$currPos = s7; s7 = peg$FAILED; @@ -1327,33 +1363,203 @@ peg$currPos = s7; s7 = peg$FAILED; } + if (s7 !== peg$FAILED) { + s6 = input.substring(s6, peg$currPos); + } else { + s6 = s7; + } + } + while (s6 !== peg$FAILED) { + s5.push(s6); + s6 = peg$currPos; + s7 = peg$currPos; + s8 = []; + s9 = peg$currPos; + s10 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 125) { + s11 = peg$c28; + peg$currPos++; + } else { + s11 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c29); } + } peg$silentFails--; - if (s7 === peg$FAILED) { - s6 = void 0; + if (s11 === peg$FAILED) { + s10 = void 0; } else { - peg$currPos = s6; - s6 = peg$FAILED; + peg$currPos = s10; + s10 = peg$FAILED; } - if (s6 !== peg$FAILED) { + if (s10 !== peg$FAILED) { if (input.length > peg$currPos) { - s7 = input.charAt(peg$currPos); + s11 = input.charAt(peg$currPos); peg$currPos++; } else { - s7 = peg$FAILED; + s11 = peg$FAILED; if (peg$silentFails === 0) { peg$fail(peg$c0); } } - if (s7 !== peg$FAILED) { - s6 = [s6, s7]; - s5 = s6; + if (s11 !== peg$FAILED) { + s10 = [s10, s11]; + s9 = s10; } else { - peg$currPos = s5; - s5 = peg$FAILED; + peg$currPos = s9; + s9 = peg$FAILED; } } else { - peg$currPos = s5; - s5 = peg$FAILED; + peg$currPos = s9; + s9 = peg$FAILED; + } + if (s9 !== peg$FAILED) { + while (s9 !== peg$FAILED) { + s8.push(s9); + s9 = peg$currPos; + s10 = peg$currPos; + peg$silentFails++; + if (input.charCodeAt(peg$currPos) === 125) { + s11 = peg$c28; + peg$currPos++; + } else { + s11 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c29); } + } + peg$silentFails--; + if (s11 === peg$FAILED) { + s10 = void 0; + } else { + peg$currPos = s10; + s10 = peg$FAILED; + } + if (s10 !== peg$FAILED) { + if (input.length > peg$currPos) { + s11 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s11 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c0); } + } + if (s11 !== peg$FAILED) { + s10 = [s10, s11]; + s9 = s10; + } else { + peg$currPos = s9; + s9 = peg$FAILED; + } + } else { + peg$currPos = s9; + s9 = peg$FAILED; + } + } + } else { + s8 = peg$FAILED; + } + if (s8 !== peg$FAILED) { + s7 = input.substring(s7, peg$currPos); + } else { + s7 = s8; + } + if (s7 !== peg$FAILED) { + s6 = input.substring(s6, peg$currPos); + } else { + s6 = s7; + } + if (s6 === peg$FAILED) { + s6 = peg$currPos; + s7 = peg$currPos; + s8 = peg$currPos; + peg$silentFails++; + s9 = peg$currPos; + if (input.charCodeAt(peg$currPos) === 125) { + s10 = peg$c28; + peg$currPos++; + } else { + s10 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c29); } + } + if (s10 !== peg$FAILED) { + s11 = peg$parse__(); + if (s11 !== peg$FAILED) { + s12 = peg$c30; + if (s12 !== peg$FAILED) { + if (input.charCodeAt(peg$currPos) === 47) { + s13 = peg$c18; + peg$currPos++; + } else { + s13 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c19); } + } + if (s13 === peg$FAILED) { + s13 = null; + } + if (s13 !== peg$FAILED) { + if (input.substr(peg$currPos, 3) === peg$c12) { + s14 = peg$c12; + peg$currPos += 3; + } else { + s14 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c13); } + } + if (s14 !== peg$FAILED) { + s10 = [s10, s11, s12, s13, s14]; + s9 = s10; + } else { + peg$currPos = s9; + s9 = peg$FAILED; + } + } else { + peg$currPos = s9; + s9 = peg$FAILED; + } + } else { + peg$currPos = s9; + s9 = peg$FAILED; + } + } else { + peg$currPos = s9; + s9 = peg$FAILED; + } + } else { + peg$currPos = s9; + s9 = peg$FAILED; + } + peg$silentFails--; + if (s9 === peg$FAILED) { + s8 = void 0; + } else { + peg$currPos = s8; + s8 = peg$FAILED; + } + if (s8 !== peg$FAILED) { + if (input.length > peg$currPos) { + s9 = input.charAt(peg$currPos); + peg$currPos++; + } else { + s9 = peg$FAILED; + if (peg$silentFails === 0) { peg$fail(peg$c0); } + } + if (s9 !== peg$FAILED) { + s8 = [s8, s9]; + s7 = s8; + } else { + peg$currPos = s7; + s7 = peg$FAILED; + } + } else { + peg$currPos = s7; + s7 = peg$FAILED; + } + if (s7 !== peg$FAILED) { + s6 = input.substring(s6, peg$currPos); + } else { + s6 = s7; + } } } + if (s5 !== peg$FAILED) { + s4 = input.substring(s4, peg$currPos); + } else { + s4 = s5; + } if (s4 !== peg$FAILED) { if (input.charCodeAt(peg$currPos) === 125) { s5 = peg$c28; diff --git a/packages/block-serialization-spec-parser/shared-tests.js b/packages/block-serialization-spec-parser/shared-tests.js index e9b90337061eeb..0eb0bcdb239506 100644 --- a/packages/block-serialization-spec-parser/shared-tests.js +++ b/packages/block-serialization-spec-parser/shared-tests.js @@ -61,6 +61,17 @@ export const jsTester = ( parse ) => () => { expect.objectContaining( { innerHTML: '

Break me

' } ), ] ) ) ); } ); + + describe( 'attack vectors', () => { + test( 'really long JSON attribute sections', () => { + const length = 100000; + const as = 'a'.repeat( length ); + let parsed; + + expect( () => parsed = parse( `` )[ 0 ] ).not.toThrow(); + expect( parsed.attrs.a ).toHaveLength( length ); + } ); + } ); }; const hasPHP = 'test' === process.env.NODE_ENV ? ( () => { @@ -77,13 +88,21 @@ const makeTest = hasPHP ? ( ...args ) => describe( ...args ) : ( ...args ) => de export const phpTester = ( name, filename ) => makeTest( name, - 'test' === process.env.NODE_ENV ? jsTester( ( doc ) => JSON.parse( require( 'child_process' ).spawnSync( - 'php', - [ '-f', filename ], - { - input: doc, - encoding: 'utf8', - timeout: 30 * 1000, // abort after 30 seconds, that's too long anyway + 'test' === process.env.NODE_ENV ? jsTester( ( doc ) => { + const process = require( 'child_process' ).spawnSync( + 'php', + [ '-f', filename ], + { + input: doc, + encoding: 'utf8', + timeout: 30 * 1000, // abort after 30 seconds, that's too long anyway + } + ); + + if ( process.status !== 0 ) { + throw new Error( process.stderr || process.stdout ); } - ).stdout ) ) : () => {} + + return JSON.parse( process.stdout ); + } ) : () => {} );