Skip to content

Commit

Permalink
Bugfix: stricter regex; disallow trailing newline
Browse files Browse the repository at this point in the history
  • Loading branch information
tvdijen committed Nov 19, 2024
1 parent 4c6d149 commit 2f6ba97
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/EngineBlock/Validator/Urn.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class EngineBlock_Validator_Urn
* Taken from: https://stackoverflow.com/a/59048720/5494155
*/
const REGEX = <<<'REGEX'
/\A(?i:urn:(?!urn:)(?<nid>[a-z0-9][a-z0-9-]{1,31}):(?<nss>(?:[-a-z0-9()+,.:=@;$_!*\'&~\/]|%[0-9a-f]{2})+)(?:\?\+(?<rcomponent>.*?))?(?:\?=(?<qcomponent>.*?))?(?:#(?<fcomponent>.*?))?)\z/
/\A(?i:urn:(?!urn:)(?<nid>[a-z0-9][a-z0-9-]{1,31}):(?<nss>(?:[-a-z0-9()+,.:=@;$_!*\'&~\/]|%[0-9a-f]{2})+)(?:\?\+(?<rcomponent>.*?))?(?:\?=(?<qcomponent>.*?))?(?:#(?<fcomponent>.*?))?)\z/D
REGEX;

public function validate(string $urn): bool
Expand Down
1 change: 1 addition & 0 deletions tests/library/EngineBlock/Test/Validator/UrnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public function invalidUrnProvider()
yield ['urn:org.openconext.licenseInfo'];
yield ['foo:bar:baz'];
yield ['urn:f:bar'];
yield ["urn:mace:dir:attribute-def:eduPersonPrincipalName\n"];
yield [' urn:collab:person:example.org:jdoe'];
yield ['urn:collab:person:example.org:jdoe '];
yield ['urn:collab:person:example org:jdoe'];
Expand Down

0 comments on commit 2f6ba97

Please sign in to comment.