Skip to content

Commit

Permalink
main: validate package name prior to resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
liushuyu committed Dec 25, 2023
1 parent 86b5f11 commit c2505e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion acbs/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from acbs.utils import (ACBSLogFormatter, ACBSLogPlainFormatter, full_line_banner, guess_subdir,
has_stamp, invoke_autobuild, make_build_dir,
print_build_timings, print_package_names, write_checksums,
generate_checksums, is_spec_legacy, check_artifact)
generate_checksums, is_spec_legacy, check_artifact, validate_package_name)


class BuildCore(object):
Expand Down Expand Up @@ -104,6 +104,8 @@ def build(self) -> None:
logging.info('Searching and resolving dependencies...')
acbs.pm.reorder_mode = self.reorder
for n, i in enumerate(self.build_queue):
if not validate_package_name(i):
raise ValueError(f'Invalid package name: `{i}`')
logging.debug(f'Finding {i}...')
print(f'[{n + 1}/{len(self.build_queue)}] {i:30}\r', end='', flush=True)
package = find_package(i, self.tree_dir, stage2=self.stage2)
Expand Down
10 changes: 10 additions & 0 deletions acbs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
if v.startswith('SIG') and not v.startswith('SIG_'))


def validate_package_name(package_name: str) -> bool:
"""
Validate package name
:param package_name: name of the package
:returns: True if the package name is valid
"""
return re.match(r'^[a-z0-9][a-z0-9\-+\.]+$', package_name) is not None


def guess_extension_name(filename: str) -> str:
"""
Guess extension name based on filename
Expand Down

0 comments on commit c2505e2

Please sign in to comment.