Fixed/improved regular expresssion for collection names (#73577)
* added changelog fragment * added a couple of tests to coll name validation
This commit is contained in:
parent
e804fccf1c
commit
920b68f5f2
4 changed files with 6 additions and 2 deletions
2
changelogs/fragments/73577-regex-fix.yml
Normal file
2
changelogs/fragments/73577-regex-fix.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- Improved/fixed regular expressions in ``validate-modules/validate_modules/schema.py`` and ``utils/collection_loader/_collection_finder.py`` (https://github.com/ansible/ansible/pull/73577).
|
|
@ -701,7 +701,7 @@ class AnsibleCollectionRef:
|
||||||
|
|
||||||
# FIXME: tighten this up to match Python identifier reqs, etc
|
# FIXME: tighten this up to match Python identifier reqs, etc
|
||||||
VALID_SUBDIRS_RE = re.compile(to_text(r'^\w+(\.\w+)*$'))
|
VALID_SUBDIRS_RE = re.compile(to_text(r'^\w+(\.\w+)*$'))
|
||||||
VALID_FQCR_RE = re.compile(to_text(r'^\w+\.\w+\.\w+(\.\w+)*$')) # can have 0-N included subdirs as well
|
VALID_FQCR_RE = re.compile(to_text(r'^\w+(\.\w+){2,}$')) # can have 0-N included subdirs as well
|
||||||
|
|
||||||
def __init__(self, collection_name, subdirs, resource, ref_type):
|
def __init__(self, collection_name, subdirs, resource, ref_type):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -45,7 +45,7 @@ def isodate(v, error_code=None):
|
||||||
return v
|
return v
|
||||||
|
|
||||||
|
|
||||||
COLLECTION_NAME_RE = re.compile('^([^.]+.[^.]+)$')
|
COLLECTION_NAME_RE = re.compile(r'^([^.]+(\.[^.]+)+)$')
|
||||||
|
|
||||||
|
|
||||||
def collection_name(v, error_code=None):
|
def collection_name(v, error_code=None):
|
||||||
|
|
|
@ -722,6 +722,7 @@ def test_fqcr_parsing_valid(ref, ref_type, expected_collection,
|
||||||
('fqcn', 'expected'),
|
('fqcn', 'expected'),
|
||||||
(
|
(
|
||||||
('ns1.coll2', True),
|
('ns1.coll2', True),
|
||||||
|
('ns1#coll2', False),
|
||||||
('def.coll3', False),
|
('def.coll3', False),
|
||||||
('ns4.return', False),
|
('ns4.return', False),
|
||||||
('assert.this', False),
|
('assert.this', False),
|
||||||
|
@ -742,6 +743,7 @@ def test_fqcn_validation(fqcn, expected):
|
||||||
[
|
[
|
||||||
('no_dots_at_all_action', 'action', ValueError, 'is not a valid collection reference'),
|
('no_dots_at_all_action', 'action', ValueError, 'is not a valid collection reference'),
|
||||||
('no_nscoll.myaction', 'action', ValueError, 'is not a valid collection reference'),
|
('no_nscoll.myaction', 'action', ValueError, 'is not a valid collection reference'),
|
||||||
|
('no_nscoll%myaction', 'action', ValueError, 'is not a valid collection reference'),
|
||||||
('ns.coll.myaction', 'bogus', ValueError, 'invalid collection ref_type'),
|
('ns.coll.myaction', 'bogus', ValueError, 'invalid collection ref_type'),
|
||||||
])
|
])
|
||||||
def test_fqcr_parsing_invalid(ref, ref_type, expected_error_type, expected_error_expression):
|
def test_fqcr_parsing_invalid(ref, ref_type, expected_error_type, expected_error_expression):
|
||||||
|
|
Loading…
Reference in a new issue