Skip to content

Commit 635f9cf

Browse files
committed
Use latest test suite data
Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent d7be020 commit 635f9cf

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/packageurl.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@
2323
# Visit https://github.com/package-url/packageurl-python for support and
2424
# download.
2525

26+
2627
from __future__ import absolute_import
2728
from __future__ import print_function
2829
from __future__ import unicode_literals
2930

3031
from collections import namedtuple
3132
from collections import OrderedDict
33+
import string
3234

3335
# Python 2 and 3 support
3436
try:
@@ -172,9 +174,31 @@ def normalize_qualifiers(qualifiers, encode=True): # NOQA
172174
'Must be a string or dict:{}'.format(repr(qualifiers)))
173175

174176
quoter = get_quoter(encode)
175-
qualifiers = {quoter(k.strip().lower()): quoter(v)
177+
qualifiers = {k.strip().lower(): quoter(v)
176178
for k, v in qualifiers if k and k.strip() and v and v.strip()}
177179

180+
valid_chars = string.ascii_letters + string.digits + '.-_'
181+
for key in qualifiers:
182+
if not key:
183+
raise ValueError('A qualifier key cannot be empty')
184+
185+
if '%' in key:
186+
raise ValueError(
187+
"A qualifier key cannot be percent encoded: {}".format(repr(key)))
188+
189+
if ' ' in key:
190+
raise ValueError(
191+
"A qualifier key cannot contain spaces: {}".format(repr(key)))
192+
193+
if not all(c in valid_chars for c in key):
194+
raise ValueError(
195+
"A qualifier key must be composed only of ASCII letters and numbers"
196+
"period, dash and underscore: {}".format(repr(key)))
197+
198+
if key[0] in string.digits:
199+
raise ValueError(
200+
"A qualifier key cannot start with a number: {}".format(repr(key)))
201+
178202
if encode:
179203
qualifiers = sorted(qualifiers.items())
180204
qualifiers = ['{}={}'.format(k, v) for k, v in qualifiers]

test-suite-data.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,5 +262,41 @@
262262
"qualifiers": null,
263263
"subpath": null,
264264
"is_invalid": false
265+
},
266+
{
267+
"description": "valid maven purl with case sensitive namespace and name",
268+
"purl": "pkg:maven/HTTPClient/HTTPClient@0.3-3",
269+
"canonical_purl": "pkg:maven/HTTPClient/HTTPClient@0.3-3",
270+
"type": "maven",
271+
"namespace": "HTTPClient",
272+
"name": "HTTPClient",
273+
"version": "0.3-3",
274+
"qualifiers": null,
275+
"subpath": null,
276+
"is_invalid": false
277+
},
278+
{
279+
"description": "valid maven purl containing a space in the version and qualifier",
280+
"purl": "pkg:maven/mygroup/myartifact@1.0.0%20Final?mykey=my%20value",
281+
"canonical_purl": "pkg:maven/mygroup/myartifact@1.0.0%20Final?mykey=my%20value",
282+
"type": "maven",
283+
"namespace": "mygroup",
284+
"name": "myartifact",
285+
"version": "1.0.0 Final",
286+
"qualifiers": {"mykey": "my value"},
287+
"subpath": null,
288+
"is_invalid": false
289+
},
290+
{
291+
"description": "checks for invalid qualifier keys",
292+
"purl": "pkg:npm/myartifact@1.0.0?in%20production=true",
293+
"canonical_purl": null,
294+
"type": "npm",
295+
"namespace": null,
296+
"name": "myartifact",
297+
"version": "1.0.0",
298+
"qualifiers": {"in production": "true"},
299+
"subpath": null,
300+
"is_invalid": true
265301
}
266302
]

0 commit comments

Comments
 (0)