Skip to content

Commit

Permalink
Update application package name checks (#685)
Browse files Browse the repository at this point in the history
* Add more checks to app name test + update error

* Fix type hint for RankProfileFields.inputs

* Support single dashes in Pyvespa app package name

* Update app package name test
  • Loading branch information
tmaregge committed Feb 26, 2024
1 parent bdedde9 commit 5ee783f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
8 changes: 7 additions & 1 deletion tests/unit/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -1305,7 +1305,13 @@ def test_invalid_name(self):
with pytest.raises(ValueError):
ApplicationPackage(name="test_app")
with pytest.raises(ValueError):
ApplicationPackage(name="test-app")
ApplicationPackage(name="test--app")
with pytest.raises(ValueError):
ApplicationPackage(name="42test-app")
with pytest.raises(ValueError):
ApplicationPackage(name="Test-app")
with pytest.raises(ValueError):
ApplicationPackage(name="test-app" + "x" * 20)


class TestFieldAlias(unittest.TestCase):
Expand Down
10 changes: 8 additions & 2 deletions vespa/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -2076,9 +2076,15 @@ def __init__(
It will create a default :class:`Schema`, :class:`QueryProfile` and :class:`QueryProfileType` that you can then
populate with specifics of your application.
"""
if not name.isalnum():
if not (
name[0].isalpha()
and name.islower()
and len(name) <= 20
and all(char.isalnum() or char == "-" for char in name)
and "--" not in name
):
raise ValueError(
"Application package name can only contain [a-zA-Z0-9], was '{}'".format(
"Application name must start with a letter, must be lowercase, can only contain [a-z0-9] and single dashes (not consecutive), and may contain no more than 20 characters, was '{}'".format(
name
)
)
Expand Down

0 comments on commit 5ee783f

Please sign in to comment.