Skip to content

Commit 2e56ea9

Browse files
committed
Removed single quote in regex for match in build test
1 parent a8b55d1 commit 2e56ea9

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

util/ActionTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ private function match(array $actions)
228228
if (is_string($expected) && $this->isRegularExpression($expected)) {
229229
$vars[':expected'] = $this->convertJavaRegexToPhp($vars[':expected']);
230230
// Add /sx preg modifier to ignore whitespace
231-
$vars[':expected'] = trim(substr($vars[':expected'], 0, -1)) . "sx'";
231+
$vars[':expected'] .= "sx";
232232
return YamlTests::render(self::TEMPLATE_MATCH_REGEX, $vars);
233233
}
234234
if ($expected instanceof stdClass && empty(get_object_vars($expected))) {
@@ -437,10 +437,12 @@ private function isRegularExpression(string $regex): bool
437437

438438
private function convertJavaRegexToPhp(string $regex): string
439439
{
440+
# remove the single quote from the beginning and end of a string
441+
$regex = trim($regex, '\'');
440442
preg_match_all('/(\/\^?)(.+)(\$?\/)/sx', $regex, $matches);
441443
if (isset($matches[2][0])) {
442444
$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]);
444446
}
445447

446448
return $regex;

util/template/test/match-regex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
$this->assertRegExp(
2-
:expected,
2+
":expected",
33
$response:value
44
);

0 commit comments

Comments
 (0)