Skip to content

Commit

Permalink
Use preg_quote() instead of escapeshellcmd to prepare string to b…
Browse files Browse the repository at this point in the history
…e a regular expression
  • Loading branch information
maks-rafalko committed Jul 25, 2021
1 parent 50f972a commit 1eff6c2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Expand Up @@ -39,11 +39,13 @@
use function array_map;
use function array_merge;
use function count;
use function escapeshellarg;
use function escapeshellcmd;
use function explode;
use Infection\AbstractTestFramework\Coverage\TestLocation;
use Infection\TestFramework\CommandLineArgumentsAndOptionsBuilder;
use function ltrim;
use function preg_quote;
use function rtrim;

/**
Expand Down Expand Up @@ -97,7 +99,7 @@ public function buildForMutant(string $configPath, string $extraOptions, array $

$usedTestCases[$testCaseString] = true;

$filterString .= escapeshellcmd($testCaseString) . '|';
$filterString .= preg_quote($testCaseString, '/') . '|';
}

$filterString = rtrim($filterString, '|') . '/';
Expand Down
Expand Up @@ -142,7 +142,7 @@ public function provideTestCases(): Generator
[
'App\Test::test_case1',
],
'/App\\\\Test::test_case1/',
'/App\\\\Test\:\:test_case1/',
];

yield '2 test cases' => [
Expand All @@ -151,7 +151,7 @@ public function provideTestCases(): Generator
'App\Test::test_case1',
'App\Test::test_case2',
],
'/App\\\\Test::test_case1|App\\\\Test::test_case2/',
'/App\\\\Test\:\:test_case1|App\\\\Test\:\:test_case2/',
];

yield '2 simple test cases, 1 with data set and special character >' => [
Expand All @@ -160,7 +160,7 @@ public function provideTestCases(): Generator
'App\Test::test_case1 with data set "With special character >"',
'App\Test::test_case2',
],
'/App\\\\Test::test_case1 with data set "With special character \\>"|App\\\\Test::test_case2/',
'/App\\\\Test\:\:test_case1 with data set "With special character \\>"|App\\\\Test\:\:test_case2/',
];

yield '2 simple test cases, 1 with data set and special character @' => [
Expand All @@ -169,7 +169,7 @@ public function provideTestCases(): Generator
'App\Test::test_case1 with data set "With special character @"',
'App\Test::test_case2',
],
'/App\\\\Test::test_case1 with data set "With special character @"|App\\\\Test::test_case2/',
'/App\\\\Test\:\:test_case1 with data set "With special character @"|App\\\\Test\:\:test_case2/',
];
}
}

0 comments on commit 1eff6c2

Please sign in to comment.