Skip to content

Commit f2e71fd

Browse files
committed
Merge branch 'fix/fix_check_name_lenght' into 'main'
fix: fix checking max name length See merge request espressif/idf-component-manager!511
2 parents e3cdf3a + e069fcb commit f2e71fd

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

idf_component_manager/cli/validations.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
1+
# SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
22
# SPDX-License-Identifier: Apache-2.0
33
import re
44
from pathlib import Path
@@ -10,7 +10,7 @@
1010
from idf_component_tools.archive_tools import ArchiveError, get_format_from_path
1111
from idf_component_tools.constants import COMPILED_COMMIT_ID_RE, COMPILED_GIT_URL_RE
1212
from idf_component_tools.manifest import WEB_DEPENDENCY_REGEX
13-
from idf_component_tools.manifest.constants import SLUG_REGEX
13+
from idf_component_tools.manifest.constants import MAX_NAME_LENGTH, SLUG_REGEX
1414
from idf_component_tools.semver import Version
1515
from idf_component_tools.semver.base import SimpleSpec
1616

@@ -19,10 +19,11 @@ def validate_name(ctx, param, value): # noqa: ARG001
1919
if value is not None:
2020
name = value.lower()
2121

22-
if not re.match(SLUG_REGEX, name):
22+
if len(name) > MAX_NAME_LENGTH or not re.match(SLUG_REGEX, name):
2323
raise click.BadParameter(
24-
f'"{name}" should consist of 2 or more letters, numbers, "-" or "_". '
25-
'It cannot start or end with "_" or "-", or have sequences of these characters.'
24+
f'"{name}" must be between 2 and {MAX_NAME_LENGTH} characters long, '
25+
'consist of letters, numbers, "-" or "_", and cannot start or end with "_" or "-", '
26+
'nor contain consecutive special characters.'
2627
)
2728
return name
2829

idf_component_tools/manifest/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
FULL_SLUG_REGEX = r'^((?:{slug}/{slug})|(?:{slug}))$'.format(slug=SLUG_BODY_REGEX)
1414
COMPILED_FULL_SLUG_REGEX = re.compile(FULL_SLUG_REGEX)
1515
WEB_DEPENDENCY_REGEX = r'^((?:{slug}/{slug})|(?:{slug}))(.*)$'.format(slug=SLUG_BODY_REGEX)
16+
MAX_NAME_LENGTH = 64
1617

1718
LINKS = ['repository', 'documentation', 'issues', 'discussion', 'url']
1819
KNOWN_INFO_METADATA_FIELDS = [

tests/cli/test_validations.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
1+
# SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD
22
# SPDX-License-Identifier: Apache-2.0
33

44
import click
@@ -24,10 +24,18 @@ def test_validate_name():
2424
assert validate_name(None, None, 'valid') == 'valid'
2525

2626

27-
def test_validate_name_invalid_input():
27+
@pytest.mark.parametrize(
28+
'invalid_name',
29+
[
30+
't',
31+
't' * 65,
32+
'тест',
33+
],
34+
)
35+
def test_validate_name_invalid_input(invalid_name):
2836
with pytest.raises(click.BadParameter) as exc_info:
29-
validate_name(None, None, 'a')
30-
assert 'should consist of 2 or more letters, numbers' in str(exc_info.value)
37+
validate_name(None, None, invalid_name)
38+
assert 'must be between 2 and 64 characters long' in str(exc_info.value)
3139

3240

3341
def test_validate_existing_dir(tmp_path):

0 commit comments

Comments
 (0)