Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Finder] Add support of no-capture regex modifier in MultiplePcreFilterIterator (available from PHP 8.2) #45980

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Finder] Add support of no-capture regex modifier in MultiplePcreFilt…
…erIterator (available from PHP 8.2)

[Finder] Add support of no-capture regex modifier in MultiplePcreFilterIterator (available from PHP 8.2)
  • Loading branch information
alexandre-daubois committed Apr 8, 2022
commit 4ca973f4624e5aea4cecc0fa12ae863576b2d574
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,13 @@ protected function isAccepted($string)
*/
protected function isRegex($str)
{
if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) {
$availableModifiers = 'imsxuADU';

if (\PHP_VERSION_ID >= 80200) {
$availableModifiers .= 'n';
}

if (preg_match('/^(.{3,}?)['.$availableModifiers.']*$/', $str, $m)) {
fabpot marked this conversation as resolved.
Show resolved Hide resolved
$start = substr($m[1], 0, 1);
$end = substr($m[1], -1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,26 @@ public function testIsRegex($string, $isRegex, $message)

public function getIsRegexFixtures()
{
return [
['foo', false, 'string'],
[' foo ', false, '" " is not a valid delimiter'],
['\\foo\\', false, '"\\" is not a valid delimiter'],
['afooa', false, '"a" is not a valid delimiter'],
['//', false, 'the pattern should contain at least 1 character'],
['/a/', true, 'valid regex'],
['/foo/', true, 'valid regex'],
['/foo/i', true, 'valid regex with a single modifier'],
['/foo/imsxu', true, 'valid regex with multiple modifiers'],
['#foo#', true, '"#" is a valid delimiter'],
['{foo}', true, '"{,}" is a valid delimiter pair'],
['[foo]', true, '"[,]" is a valid delimiter pair'],
['(foo)', true, '"(,)" is a valid delimiter pair'],
['<foo>', true, '"<,>" is a valid delimiter pair'],
['*foo.*', false, '"*" is not considered as a valid delimiter'],
['?foo.?', false, '"?" is not considered as a valid delimiter'],
];
yield ['foo', false, 'string'];
yield [' foo ', false, '" " is not a valid delimiter'];
yield ['\\foo\\', false, '"\\" is not a valid delimiter'];
yield ['afooa', false, '"a" is not a valid delimiter'];
yield ['//', false, 'the pattern should contain at least 1 character'];
yield ['/a/', true, 'valid regex'];
yield ['/foo/', true, 'valid regex'];
yield ['/foo/i', true, 'valid regex with a single modifier'];
yield ['/foo/imsxu', true, 'valid regex with multiple modifiers'];
yield ['#foo#', true, '"#" is a valid delimiter'];
yield ['{foo}', true, '"{,}" is a valid delimiter pair'];
yield ['[foo]', true, '"[,]" is a valid delimiter pair'];
yield ['(foo)', true, '"(,)" is a valid delimiter pair'];
yield ['<foo>', true, '"<,>" is a valid delimiter pair'];
yield ['*foo.*', false, '"*" is not considered as a valid delimiter'];
yield ['?foo.?', false, '"?" is not considered as a valid delimiter'];

if (\PHP_VERSION_ID >= 80200) {
yield ['/foo/n', true, 'valid regex with the no-capture modifier'];
}
}
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.