Resolve homebrew and homebrew_cask package name validation issues (#1038)

Add basic regression tests
Add changelog
Rename _create_regex_group to better suit function
Fix '-' use in Homebrew validation
This commit is contained in:
MichaelWasher 2020-10-28 10:46:49 +13:00 committed by GitHub
parent 4842f67da1
commit 4c379bd3b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 62 additions and 14 deletions

View file

@ -168,7 +168,7 @@ class HomebrewException(Exception):
# utils ------------------------------------------------------------------- {{{
def _create_regex_group(s):
def _create_regex_group_complement(s):
lines = (line.strip() for line in s.split('\n') if line.strip())
chars = filter(None, (line.split('#')[0].strip() for line in lines))
group = r'[^' + r''.join(chars) + r']'
@ -186,7 +186,7 @@ class Homebrew(object):
: # colons
{sep} # the OS-specific path separator
. # dots
- # dashes
\- # dashes
'''.format(sep=os.path.sep)
VALID_BREW_PATH_CHARS = r'''
@ -194,7 +194,7 @@ class Homebrew(object):
\s # spaces
{sep} # the OS-specific path separator
. # dots
- # dashes
\- # dashes
'''.format(sep=os.path.sep)
VALID_PACKAGE_CHARS = r'''
@ -202,14 +202,14 @@ class Homebrew(object):
. # dots
/ # slash (for taps)
\+ # plusses
- # dashes
\- # dashes
: # colons (for URLs)
@ # at-sign
'''
INVALID_PATH_REGEX = _create_regex_group(VALID_PATH_CHARS)
INVALID_BREW_PATH_REGEX = _create_regex_group(VALID_BREW_PATH_CHARS)
INVALID_PACKAGE_REGEX = _create_regex_group(VALID_PACKAGE_CHARS)
INVALID_PATH_REGEX = _create_regex_group_complement(VALID_PATH_CHARS)
INVALID_BREW_PATH_REGEX = _create_regex_group_complement(VALID_BREW_PATH_CHARS)
INVALID_PACKAGE_REGEX = _create_regex_group_complement(VALID_PACKAGE_CHARS)
# /class regexes ----------------------------------------------- }}}
# class validations -------------------------------------------- {{{