Skip to content

Commit 57a83a4

Browse files
committed
PHP/PregQuoteDelimiter: add tests for namespaced names
1 parent 93225ec commit 57a83a4

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.inc

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,21 @@ preg_quote($keywords, '/'); // OK.
44
preg_quote( $keywords, '`' ); // OK.
55

66
preg_quote($keywords); // Warning.
7-
$textbody = preg_replace ( "/" . preg_quote($word) . "/", // Warning
7+
$textbody = preg_replace ( "/" . \PREG_quote($word) . "/", // Warning
88
"<i>" . $word . "</i>",
99
$textbody );
1010

1111
// Safeguard support for PHP 8.0+ named parameters.
1212
preg_quote(delimiter: '#', str: $keywords); // OK.
1313
preg_quote(str: $keywords); // Warning.
14-
preg_quote(str: $keywords, delimitter: '#'); // Warning (typo in param name).
14+
Preg_QUOTE(str: $keywords, delimitter: '#'); // Warning (typo in param name).
1515
preg_quote(delimiter: '#'); // OK. Invalid function call, but that's not the concern of this sniff.
16+
17+
/*
18+
* Safeguard correct handling of all types of namespaced function calls.
19+
*/
20+
\preg_quote($keywords); // Warning.
21+
MyNamespace\preg_quote($keywords); // Ok.
22+
\MyNamespace\preg_quote($keywords); // Ok.
23+
namespace\preg_quote($keywords); // The sniff should start flagging this once it can resolve relative namespaces.
24+
namespace\Sub\preg_quote($keywords); // Ok.

WordPress/Tests/PHP/PregQuoteDelimiterUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function getWarningList() {
4040
7 => 1,
4141
13 => 1,
4242
14 => 1,
43+
20 => 1,
4344
);
4445
}
4546
}

0 commit comments

Comments
 (0)