Skip to content

Commit 0995186

Browse files
committed
bool() cast during URL path validation not needed
1 parent 07ca215 commit 0995186

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/murfey/server/api/bootstrap.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -686,15 +686,15 @@ def get_index_package_metadata(
686686
logger.debug(f"Received request to access {str(request.url)}")
687687

688688
# Validate path to the package metadata
689-
if not all(bool(re.fullmatch(r"[\w\-]{1,2}", char)) for char in (c1, c2)):
689+
if any(not re.fullmatch(r"[\w\-]{1,2}", char) for char in (c1, c2)):
690690
raise ValueError("Invalid path to package metadata")
691691

692692
if len(c1) == 1 and not c1 == "3":
693693
raise ValueError("Invalid path to package metadata")
694694
if c1 == "3" and not len(c2) == 1:
695695
raise ValueError("Invalid path to package metadata")
696696

697-
if not bool(re.fullmatch(r"[\w\-]+", package)):
697+
if not re.fullmatch(r"[\w\-]+", package):
698698
raise ValueError("Invalid package name")
699699

700700
# Request and return the metadata as a JSON file
@@ -725,7 +725,7 @@ def get_index_package_metadata_for_short_package_names(
725725
# Validate path to crate
726726
if n not in ("1", "2"):
727727
raise ValueError("Invalid path to package metadata")
728-
if not bool(re.fullmatch(r"[\w\-]{1,2}", package)):
728+
if not re.fullmatch(r"[\w\-]{1,2}", package):
729729
raise ValueError("Invalid package name")
730730

731731
# Request and return the metadata as a JSON file
@@ -754,9 +754,9 @@ def get_rust_api_package_index(
754754
logger.debug(f"Received request to access {str(request.url)}")
755755

756756
# Validate package name
757-
if package and not bool(re.fullmatch(r"[\w\-]+", package)):
757+
if package and not re.fullmatch(r"[\w\-]+", package):
758758
raise ValueError("Invalid package name")
759-
if cursor and not bool(re.fullmatch(r"[a-zA-Z0-9]+", cursor)):
759+
if cursor and not re.fullmatch(r"[a-zA-Z0-9]+", cursor):
760760
raise ValueError("Invalid cursor")
761761

762762
# Formulate the search query to pass to the crates page
@@ -790,7 +790,7 @@ def get_rust_api_package_info(
790790
logger.debug(f"Received request to access {str(request.url)}")
791791

792792
# Validate package name
793-
if not bool(re.fullmatch(r"[\w\-]+", package)):
793+
if not re.fullmatch(r"[\w\-]+", package):
794794
raise ValueError("Invalid package name")
795795

796796
# Return JSON of the package's page
@@ -814,7 +814,7 @@ def get_rust_api_package_versions(
814814
logger.debug(f"Received request to access {str(request.url)}")
815815

816816
# Validate crate name
817-
if not bool(re.fullmatch(r"[\w\-]+", package)):
817+
if not re.fullmatch(r"[\w\-]+", package):
818818
raise ValueError("Invalid package name")
819819

820820
# Return JSON of the package's version information
@@ -840,12 +840,12 @@ def get_rust_api_package_download(
840840
logger.debug(f"Received request to access {str(request.url)}")
841841

842842
# Validate package name
843-
if not bool(re.fullmatch(r"[\w\-]+", package)):
843+
if not re.fullmatch(r"[\w\-]+", package):
844844
raise ValueError("Invalid package name")
845845
# Validate version number
846846
# Not all developers adhere to guidelines when versioning their packages, so
847847
# '-', '_', '+', as well as letters can also be present in this field.
848-
if not bool(re.fullmatch(r"[\w\-\.\+]+", version)):
848+
if not re.fullmatch(r"[\w\-\.\+]+", version):
849849
raise ValueError("Invalid version number")
850850

851851
# Request and return package
@@ -880,9 +880,9 @@ def get_rust_package_download(
880880
logger.debug(f"Received request to access {str(request.url)}")
881881

882882
# Validate package and version
883-
if not bool(re.fullmatch(r"[\w\-]+", package)):
883+
if not re.fullmatch(r"[\w\-]+", package):
884884
raise ValueError("Invalid package name")
885-
if not bool(re.fullmatch(r"[\w\-\.\+]+", version)):
885+
if not re.fullmatch(r"[\w\-\.\+]+", version):
886886
raise ValueError("Invalid version number")
887887

888888
# Request and return crate from https://static.crates.io
@@ -926,12 +926,12 @@ def get_rust_package_crate(
926926
logger.debug(f"Received request to access {str(request.url)}")
927927

928928
# Validate crate and package names
929-
if not bool(re.fullmatch(r"[\w\-]+", package)):
929+
if not re.fullmatch(r"[\w\-]+", package):
930930
raise ValueError("Invalid package name")
931931
if not crate.endswith(".crate"):
932932
raise ValueError("This is a not a Rust crate")
933933
# Rust crates follow a '{crate}-{version}.crate' structure
934-
if not bool(re.fullmatch(r"[\w\-]+\-[0-9\.]+\.crate", crate)):
934+
if not re.fullmatch(r"[\w\-]+\-[0-9\.]+\.crate", crate):
935935
raise ValueError("Invalid crate name")
936936

937937
# Request and return package

0 commit comments

Comments
 (0)