Skip to content

Commit

Permalink
Update loose config to use allowParamFlagsAnywhere
Browse files Browse the repository at this point in the history
Followup to #150
  • Loading branch information
spaze committed Dec 7, 2022
1 parent cb8db9c commit c3ffa8b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion disallowed-loose-calls.neon
Expand Up @@ -8,5 +8,5 @@ parameters:
-
function: 'htmlspecialchars()'
message: 'set the $flags parameter to `ENT_QUOTES` to also convert single quotes to entities to prevent some HTML injection bugs'
allowParamsAnywhere:
allowParamFlagsAnywhere:
2: ::ENT_QUOTES
14 changes: 10 additions & 4 deletions tests/Configs/LooseConfigFunctionCallsTest.php
Expand Up @@ -21,9 +21,14 @@ protected function getRule(): Rule
$config = Neon::decode(file_get_contents(__DIR__ . '/../../disallowed-loose-calls.neon'));
// emulate how the real config loader expands constants that are used in the config file above (e.g. ::ENT_QUOTES)
foreach ($config['parameters']['disallowedFunctionCalls'] as &$call) {
foreach ($call['allowParamsAnywhere'] as &$param) {
if (is_string($param) && preg_match('/^::([A-Z0-9_]+)$/', $param, $matches)) {
$param = constant($matches[1]);
foreach (['allowParamsAnywhere', 'allowParamFlagsAnywhere'] as $key) {
if (!isset($call[$key])) {
continue;
}
foreach ($call[$key] as &$param) {
if (is_string($param) && preg_match('/^::([A-Z0-9_]+)$/', $param, $matches)) {
$param = constant($matches[1]);
}
}
}
}
Expand All @@ -43,7 +48,8 @@ public function testRule(): void
['Calling in_array() is forbidden, set the third parameter $strict to `true` to also check the types to prevent type juggling bugs', 4],
['Calling in_array() is forbidden, set the third parameter $strict to `true` to also check the types to prevent type juggling bugs', 6],
['Calling htmlspecialchars() is forbidden, set the $flags parameter to `ENT_QUOTES` to also convert single quotes to entities to prevent some HTML injection bugs', 7],
['Calling htmlspecialchars() is forbidden, set the $flags parameter to `ENT_QUOTES` to also convert single quotes to entities to prevent some HTML injection bugs', 10],
['Calling htmlspecialchars() is forbidden, set the $flags parameter to `ENT_QUOTES` to also convert single quotes to entities to prevent some HTML injection bugs', 12],
['Calling htmlspecialchars() is forbidden, set the $flags parameter to `ENT_QUOTES` to also convert single quotes to entities to prevent some HTML injection bugs', 13],
]);
}

Expand Down
3 changes: 3 additions & 0 deletions tests/src/configs/looseCalls.php
Expand Up @@ -7,4 +7,7 @@
htmlspecialchars('foo');
htmlspecialchars('foo', ENT_QUOTES);
htmlspecialchars('foo', 3);
htmlspecialchars('foo', ENT_QUOTES | ENT_HTML5);
htmlspecialchars('foo', 51); // ENT_QUOTES | ENT_HTML5
htmlspecialchars('foo', ENT_XHTML);
htmlspecialchars('foo', 4);

0 comments on commit c3ffa8b

Please sign in to comment.