From 661c038e325e016bcee9953547cb34b413eb7ff8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=BCsges?= Date: Mon, 17 Feb 2020 14:01:52 +0100 Subject: [PATCH 1/2] Fix remove all template tags --- src/Compiler.php | 2 +- tests/fixtures/vue-if/if-with-template.twig | 7 +++++++ tests/fixtures/vue-if/if-with-template.vue | 10 ++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/fixtures/vue-if/if-with-template.twig create mode 100644 tests/fixtures/vue-if/if-with-template.vue diff --git a/src/Compiler.php b/src/Compiler.php index 3d589dc..e171efa 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -121,7 +121,7 @@ public function convert(): string $html = $this->addVariableBlocks($html); $html = $this->replacePlaceholders($html); - $html = preg_replace('/\\s*(.*?)\s*\<\/template\>/ism', '$1', $html); + $html = trim(preg_replace('/<\/?template[^>]*?>/i', '', $html)); if ($this->stripWhitespace) { $html = $this->stripWhitespace($html); diff --git a/tests/fixtures/vue-if/if-with-template.twig b/tests/fixtures/vue-if/if-with-template.twig new file mode 100644 index 0000000..4c81743 --- /dev/null +++ b/tests/fixtures/vue-if/if-with-template.twig @@ -0,0 +1,7 @@ +
+ {% if someVar %} +

Headline

+ {% else %} +

Other headline

+ {% endif %} +
\ No newline at end of file diff --git a/tests/fixtures/vue-if/if-with-template.vue b/tests/fixtures/vue-if/if-with-template.vue new file mode 100644 index 0000000..a2d027b --- /dev/null +++ b/tests/fixtures/vue-if/if-with-template.vue @@ -0,0 +1,10 @@ + From f7cec54891f5f9526749fb5932a07c994f259a23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20H=C3=BCsges?= Date: Mon, 17 Feb 2020 14:31:24 +0100 Subject: [PATCH 2/2] Fix remove all template tags --- src/Compiler.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Compiler.php b/src/Compiler.php index e171efa..86e18e8 100644 --- a/src/Compiler.php +++ b/src/Compiler.php @@ -121,7 +121,8 @@ public function convert(): string $html = $this->addVariableBlocks($html); $html = $this->replacePlaceholders($html); - $html = trim(preg_replace('/<\/?template[^>]*?>/i', '', $html)); + $html = preg_replace('/\\s*(.*)\s*\<\/template\>/ism', '$1', $html); + $html = preg_replace('/<\/?template[^>]*?>/i', '', $html); if ($this->stripWhitespace) { $html = $this->stripWhitespace($html);