Skip to content

Commit 88ffc4f

Browse files
committed
Remove unnecessary SafeString constructor parameter
1 parent 52ef73a commit 88ffc4f

File tree

3 files changed

+5
-17
lines changed

3 files changed

+5
-17
lines changed

src/Parser.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ protected static function getExpression(string $v, Context $context, int|string
113113
}
114114

115115
if (str_contains($v, ']')) {
116-
preg_match_all(Token::VARNAME_SEARCH, $v, $matchedAll);
116+
preg_match_all('/(\\[[^\\]]+\\]|[^\\[\\]\\.]+)/', $v, $matchedAll);
117117
} else {
118118
preg_match_all('/([^.\\/]+)/', $v, $matchedAll);
119119
}
@@ -302,8 +302,8 @@ protected static function detectQuote(string $string): ?array
302302
}
303303

304304
// begin with \' without ending '
305-
if (preg_match('/^\'[^\']*$/', $string)) {
306-
return ['\'', 0];
305+
if (preg_match("/^'[^']*$/", $string)) {
306+
return ["'", 0];
307307
}
308308

309309
// '="' exists without ending '"'

src/SafeString.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,9 @@ class SafeString implements \Stringable
1010

1111
private string $string;
1212

13-
/**
14-
* @param string $str input string
15-
* @param bool|string $escape false to not escape, true to escape, 'encq' to escape as handlebars.js
16-
*/
17-
public function __construct(string $str, bool|string $escape = false)
13+
public function __construct(string $string)
1814
{
19-
$this->string = $escape ? ($escape === 'encq' ? Encoder::encq($str) : Encoder::enc($str)) : $str;
15+
$this->string = $string;
2016
}
2117

2218
public function __toString()
@@ -32,11 +28,6 @@ public static function stripExtendedComments(string $template): string
3228
return preg_replace(static::EXTENDED_COMMENT_SEARCH, '{{! }}', $template);
3329
}
3430

35-
/**
36-
* Escape template
37-
*
38-
* @param string $template handlebars template string
39-
*/
4031
public static function escapeTemplate(string $template): string
4132
{
4233
return addcslashes($template, '\\');

src/Token.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
*/
88
final class Token
99
{
10-
// RegExps
11-
public const VARNAME_SEARCH = '/(\\[[^\\]]+\\]|[^\\[\\]\\.]+)/';
12-
1310
// Positions of matched token
1411
public const POS_LOTHER = 1;
1512
public const POS_LSPACE = 2;

0 commit comments

Comments
 (0)