From acb407eff5681dd5ffeb3ae4e83070859f55aca9 Mon Sep 17 00:00:00 2001 From: Bhumit267 Date: Thu, 5 Nov 2026 22:09:43 +0530 Subject: [PATCH] fix(conversions): reject empty negative binary input in bin_to_hexadecimal --- conversions/binary_to_hexadecimal.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/conversions/binary_to_hexadecimal.py b/conversions/binary_to_hexadecimal.py index a3855bb70b52..fb0e40171583 100644 --- a/conversions/binary_to_hexadecimal.py +++ b/conversions/binary_to_hexadecimal.py @@ -36,6 +36,14 @@ def bin_to_hexadecimal(binary_str: str) -> str: Traceback (most recent call last): ... ValueError: Empty string was passed to the function + >>> bin_to_hexadecimal('-') + Traceback (most recent call last): + ... + ValueError: Non-binary value was passed to the function + >>> bin_to_hexadecimal(' - ') + Traceback (most recent call last): + ... + ValueError: Non-binary value was passed to the function """ # Sanitising parameter binary_str = str(binary_str).strip() @@ -45,7 +53,7 @@ def bin_to_hexadecimal(binary_str: str) -> str: raise ValueError("Empty string was passed to the function") is_negative = binary_str[0] == "-" binary_str = binary_str[1:] if is_negative else binary_str - if not all(char in "01" for char in binary_str): + if not binary_str or not all(char in "01" for char in binary_str): raise ValueError("Non-binary value was passed to the function") binary_str = (