Skip to content

Commit

Permalink
minor #4219 Improve deprecation message (ruudk)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.x branch.

Discussion
----------

Improve deprecation message

See #4199 (comment)

/cc `@stof` `@fabpot`

Commits
-------

9010792 Improve deprecation message
  • Loading branch information
fabpot committed Aug 21, 2024
2 parents 302971f + 9010792 commit e0077a4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand All @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/LexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
];
}

Expand Down

0 comments on commit e0077a4

Please sign in to comment.