1
0
Fork 0

Fix backtracking in name validation regex

pull/10799/head
Jordi Boggiano 2022-05-24 14:32:18 +02:00
parent 2837585e47
commit 44a52e4157
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
3 changed files with 4 additions and 4 deletions

View File

@ -6,7 +6,7 @@
"name": { "name": {
"type": "string", "type": "string",
"description": "Package name, including 'vendor-name/' prefix.", "description": "Package name, including 'vendor-name/' prefix.",
"pattern": "^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$" "pattern": "^[a-z0-9]([_.-]?[a-z0-9]++)*+/[a-z0-9](([_.]|-{1,2})?[a-z0-9]++)*+$"
}, },
"description": { "description": {
"type": "string", "type": "string",

View File

@ -456,7 +456,7 @@ class ValidatingArrayLoader implements LoaderInterface
return null; return null;
} }
if (!Preg::isMatch('{^[a-z0-9](?:[_.-]?[a-z0-9]+)*/[a-z0-9](?:(?:[_.]?|-{0,2})[a-z0-9]+)*$}iD', $name)) { if (!Preg::isMatch('{^[a-z0-9](?:[_.-]?[a-z0-9]++)*+/[a-z0-9](?:(?:[_.]|-{1,2})?[a-z0-9]++)*+$}iD', $name)) {
return $name.' is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or _. The complete name should match "^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$".'; return $name.' is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or _. The complete name should match "^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$".';
} }

View File

@ -25,9 +25,9 @@ class ComposerSchemaTest extends TestCase
$expectedError = array( $expectedError = array(
array( array(
'property' => 'name', 'property' => 'name',
'message' => 'Does not match the regex pattern ^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$', 'message' => 'Does not match the regex pattern ^[a-z0-9]([_.-]?[a-z0-9]++)*+/[a-z0-9](([_.]|-{1,2})?[a-z0-9]++)*+$',
'constraint' => 'pattern', 'constraint' => 'pattern',
'pattern' => '^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9](([_.]?|-{0,2})[a-z0-9]+)*$', 'pattern' => '^[a-z0-9]([_.-]?[a-z0-9]++)*+/[a-z0-9](([_.]|-{1,2})?[a-z0-9]++)*+$',
), ),
); );