From 19ac08cd9c94b434a01a86e6d96b445730d77a34 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 17 Jan 2024 18:37:41 +0100 Subject: [PATCH] Extractor: fix escaping quotes when converting from HEREDOC [Closes #151] --- src/PhpGenerator/Extractor.php | 2 +- tests/PhpGenerator/expected/ClassType.from.bodies.expect | 2 +- tests/PhpGenerator/expected/Extractor.bodies.expect | 2 +- tests/PhpGenerator/expected/Extractor.bodies.resolving.expect | 2 +- .../PhpGenerator/expected/Extractor.bodies.unresolving.expect | 2 +- tests/PhpGenerator/fixtures/bodies.php | 4 ++-- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/PhpGenerator/Extractor.php b/src/PhpGenerator/Extractor.php index a6259dab..f12e1435 100644 --- a/src/PhpGenerator/Extractor.php +++ b/src/PhpGenerator/Extractor.php @@ -130,7 +130,7 @@ private function prepareReplacements(array $nodes): array $replacements[] = [ $node->getStartFilePos() - $start, $node->getEndFilePos() - $start, - $quote . addcslashes($node->value, "\x00..\x1F") . $quote, + $quote . addcslashes($node->value, "\x00..\x1F\"") . $quote, ]; } } elseif ($node instanceof Node\Scalar\Encapsed) { diff --git a/tests/PhpGenerator/expected/ClassType.from.bodies.expect b/tests/PhpGenerator/expected/ClassType.from.bodies.expect index a251549e..ec2b79e5 100644 --- a/tests/PhpGenerator/expected/ClassType.from.bodies.expect +++ b/tests/PhpGenerator/expected/ClassType.from.bodies.expect @@ -85,7 +85,7 @@ abstract class Class7 $s3 = "a\n\t{$b}\n\t\t$c" ; - $s3 = "a\n\tb\n\t\tc" + $s4 = "a\n\tb\n\t\tc 'q1' \"q2\"" ; // inline HTML is not supported ?> diff --git a/tests/PhpGenerator/expected/Extractor.bodies.expect b/tests/PhpGenerator/expected/Extractor.bodies.expect index 6e321ade..7238a1c4 100644 --- a/tests/PhpGenerator/expected/Extractor.bodies.expect +++ b/tests/PhpGenerator/expected/Extractor.bodies.expect @@ -95,7 +95,7 @@ abstract class Class7 $s3 = "a\n\t{$b}\n\t\t$c" ; - $s3 = "a\n\tb\n\t\tc" + $s4 = "a\n\tb\n\t\tc 'q1' \"q2\"" ; // inline HTML is not supported ?> diff --git a/tests/PhpGenerator/expected/Extractor.bodies.resolving.expect b/tests/PhpGenerator/expected/Extractor.bodies.resolving.expect index cb64aca7..e4ed7da6 100644 --- a/tests/PhpGenerator/expected/Extractor.bodies.resolving.expect +++ b/tests/PhpGenerator/expected/Extractor.bodies.resolving.expect @@ -90,7 +90,7 @@ abstract class Class7 $s3 = "a\n\t{$b}\n\t\t$c" ; - $s3 = "a\n\tb\n\t\tc" + $s4 = "a\n\tb\n\t\tc 'q1' \"q2\"" ; // inline HTML is not supported ?> diff --git a/tests/PhpGenerator/expected/Extractor.bodies.unresolving.expect b/tests/PhpGenerator/expected/Extractor.bodies.unresolving.expect index 6ae6f85c..41c25a4a 100644 --- a/tests/PhpGenerator/expected/Extractor.bodies.unresolving.expect +++ b/tests/PhpGenerator/expected/Extractor.bodies.unresolving.expect @@ -90,7 +90,7 @@ abstract class Class7 $s3 = "a\n\t{$b}\n\t\t$c" ; - $s3 = "a\n\tb\n\t\tc" + $s4 = "a\n\tb\n\t\tc 'q1' \"q2\"" ; // inline HTML is not supported ?> diff --git a/tests/PhpGenerator/fixtures/bodies.php b/tests/PhpGenerator/fixtures/bodies.php index 99bc0a57..a15e7fc5 100644 --- a/tests/PhpGenerator/fixtures/bodies.php +++ b/tests/PhpGenerator/fixtures/bodies.php @@ -94,10 +94,10 @@ function complex() $c DOC ; - $s3 = <<<'DOC' + $s4 = <<<'DOC' a b - c + c 'q1' "q2" DOC ; // inline HTML is not supported