From 90107929daf0cc3ebdbcc41bc963e0371ca61ddd Mon Sep 17 00:00:00 2001 From: Ruud Kamphuis Date: Wed, 21 Aug 2024 19:36:27 +0200 Subject: [PATCH] Improve deprecation message See https://github.com/twigphp/Twig/pull/4199#discussion_r1723456834 --- src/Lexer.php | 4 ++-- tests/LexerTest.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Lexer.php b/src/Lexer.php index 78b07156506..28feaa2c128 100644 --- a/src/Lexer.php +++ b/src/Lexer.php @@ -418,7 +418,7 @@ private function stripcslashes(string $str, string $quoteType): string $result .= $nextChar; } elseif ("'" === $nextChar || '"' === $nextChar) { if ($nextChar !== $quoteType) { - trigger_deprecation('twig/twig', '3.12', 'Character "%s" at position %d does not need to be escaped anymore.', $nextChar, $i + 1); + trigger_deprecation('twig/twig', '3.12', 'Character "%s" at position %d should not be escaped; the "\" character is ignored in Twig v3 but will not be in v4. Please remove the extra "\" character.', $nextChar, $i + 1); } $result .= $nextChar; } elseif ('#' === $nextChar && $i + 1 < $length && '{' === $str[$i + 1]) { @@ -437,7 +437,7 @@ private function stripcslashes(string $str, string $quoteType): string } $result .= \chr(octdec($octal)); } else { - trigger_deprecation('twig/twig', '3.12', \sprintf('Character "%s" at position %d does not need to be escaped anymore.', $nextChar, $i + 1)); + trigger_deprecation('twig/twig', '3.12', 'Character "%s" at position %d should not be escaped; the "\" character is ignored in Twig v3 but will not be in v4. Please remove the extra "\" character.', $nextChar, $i + 1); $result .= $nextChar; } diff --git a/tests/LexerTest.php b/tests/LexerTest.php index 158836ac447..f07a0868412 100644 --- a/tests/LexerTest.php +++ b/tests/LexerTest.php @@ -252,17 +252,17 @@ public function getStringWithEscapedDelimiterProducingDeprecation() yield '{{ \'App\Test\' }} => AppTest' => [ '{{ \'App\\Test\' }}', 'AppTest', - 'Since twig/twig 3.12: Character "T" at position 5 does not need to be escaped anymore.', + 'Since twig/twig 3.12: Character "T" at position 5 should not be escaped; the "\" character is ignored in Twig v3 but will not be in v4. Please remove the extra "\" character.', ]; yield '{{ "foo \\\' bar" }} => foo \' bar' => [ '{{ "foo \\\' bar" }}', 'foo \' bar', - "Since twig/twig 3.12: Character \"'\" at position 6 does not need to be escaped anymore.", + 'Since twig/twig 3.12: Character "\'" at position 6 should not be escaped; the "\" character is ignored in Twig v3 but will not be in v4. Please remove the extra "\" character.', ]; yield '{{ \'foo \" bar\' }} => foo " bar' => [ '{{ \'foo \\" bar\' }}', 'foo " bar', - 'Since twig/twig 3.12: Character """ at position 6 does not need to be escaped anymore.', + 'Since twig/twig 3.12: Character """ at position 6 should not be escaped; the "\" character is ignored in Twig v3 but will not be in v4. Please remove the extra "\" character.', ]; }