Skip to content

Commit

Permalink
Merge pull request #1418 from njgheorghita/ethpm-fix-regex
Browse files Browse the repository at this point in the history
[ethPM] Add expression begin/close chars to package name regex
  • Loading branch information
njgheorghita authored Aug 12, 2019
2 parents 01380b5 + df0df59 commit 4b146df
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion ethpm/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
REGISTRY_URI_SCHEME = "erc1319"

PACKAGE_NAME_REGEX = "[a-zA-Z][-_a-zA-Z0-9]{0,255}"
PACKAGE_NAME_REGEX = "^[a-zA-Z][-_a-zA-Z0-9]{0,255}$"

DEFAULT_IPFS_BACKEND = "ethpm.backends.ipfs.InfuraIPFSBackend"

Expand Down
2 changes: 1 addition & 1 deletion ethpm/validation/uri.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def validate_registry_uri(uri: str) -> None:
)
validate_registry_uri_scheme(scheme)
validate_registry_uri_authority(authority)
pkg_name = pkg_path.lstrip("/")
pkg_name = pkg_path.strip("/")
if pkg_name:
validate_package_name(pkg_name)
if not pkg_name and version:
Expand Down
36 changes: 36 additions & 0 deletions tests/ethpm/validation/test_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from ethpm.validation.package import (
validate_manifest_version,
validate_package_name,
)


Expand Down Expand Up @@ -215,3 +216,38 @@ def test_validate_meta_object_validates(meta, extra_fields):
def test_validate_meta_object_invalidates(meta, extra_fields):
with pytest.raises(EthPMValidationError):
validate_meta_object(meta, allow_extra_meta_fields=extra_fields)


@pytest.mark.parametrize(
"package_name",
(
"valid",
"Valid",
"pkg1",
"pkg_1",
"pkg-1",
"wallet0",
"wallet_",
"wallet-",
"x" * 256,
)
)
def test_validate_package_name_with_valid_package_names(package_name):
assert validate_package_name(package_name) is None


@pytest.mark.parametrize(
"package_name",
(
"",
"0",
"_invalid",
"-invalid",
".invalid",
"wallet.bad",
"x" * 257,
)
)
def test_validate_package_name_raises_exception_for_invalid_names(package_name):
with pytest.raises(EthPMValidationError):
validate_package_name(package_name)

0 comments on commit 4b146df

Please sign in to comment.