@@ -228,7 +228,7 @@ private function match(array $actions)
228
228
if (is_string($expected) && $this->isRegularExpression($expected)) {
229
229
$vars[':expected'] = $this->convertJavaRegexToPhp($vars[':expected']);
230
230
// Add /sx preg modifier to ignore whitespace
231
- $vars[':expected'] = trim(substr($vars[':expected'], 0, -1)) . "sx' ";
231
+ $vars[':expected'] .= "sx";
232
232
return YamlTests::render(self::TEMPLATE_MATCH_REGEX, $vars);
233
233
}
234
234
if ($expected instanceof stdClass && empty(get_object_vars($expected))) {
@@ -437,10 +437,12 @@ private function isRegularExpression(string $regex): bool
437
437
438
438
private function convertJavaRegexToPhp(string $regex): string
439
439
{
440
+ # remove the single quote from the beginning and end of a string
441
+ $regex = trim($regex, '\'');
440
442
preg_match_all('/(\/\^?)(.+)(\$?\/)/sx', $regex, $matches);
441
443
if (isset($matches[2][0])) {
442
444
$matches[2][0] = str_replace('/', '\/', $matches[2][0]);
443
- return sprintf("' %s%s%s' ", $matches[1][0], $matches[2][0], $matches[3][0]);
445
+ return sprintf("%s%s%s", $matches[1][0], $matches[2][0], $matches[3][0]);
444
446
}
445
447
446
448
return $regex;
0 commit comments