Skip to content

Commit

Permalink
feat: ajouter une validation regex pour les paramètres de requête uti…
Browse files Browse the repository at this point in the history
…lisateur
  • Loading branch information
trivoallan committed Nov 9, 2024
1 parent 139a0c9 commit 7f53469
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ dashboard:
rules:
query:
admin: "true"
user:
regex: "/^user[0-9]+$/"
```

## Diagrammes C4
Expand Down
3 changes: 2 additions & 1 deletion config/bundles.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ homepage:
extensions: [css]
rules:
pathContains: /homepage

dashboard:
javascript:
directories: [dashboard/js]
extensions: [js]
rules:
query:
admin: true
user:
regex: /^user[0-9]+$/
10 changes: 8 additions & 2 deletions src/AssetGatherer.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,14 @@ private function bundleMatchesRequest(array $rules, ServerRequestInterface $requ
case 'query':
$queryParams = $request->getQueryParams();
foreach ($ruleValue as $queryKey => $queryValue) {
if (($queryParams[$queryKey] ?? '') !== $queryValue) {
return false;
if (is_array($queryValue)) {
if (!isset($queryParams[$queryKey]) || !preg_match($queryValue['regex'], $queryParams[$queryKey])) {
return false;
}
} else {
if (($queryParams[$queryKey] ?? '') !== $queryValue) {
return false;
}
}
}
break;
Expand Down

0 comments on commit 7f53469

Please sign in to comment.