Skip to content

Commit 50c1595

Browse files
author
Sergey Vasilyev
committed
Cease detecting MD5 hashes as UUIDs
It fails the comparison anyway — because of casing & dashes not fitting into alphanumeric ranges/slices.
1 parent be24cb2 commit 50c1595

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

data_diff/utils.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,14 @@ def safezip(*args):
4343
return zip(*args)
4444

4545

46-
def is_uuid(u):
46+
UUID_PATTERN = re.compile(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", re.I)
47+
48+
49+
def is_uuid(u: str) -> bool:
50+
# E.g., hashlib.md5(b'hello') is a 32-letter hex number, but not an UUID.
51+
# It would fail UUID-like comparison (< & >) because of casing and dashes.
52+
if not UUID_PATTERN.fullmatch(u):
53+
return False
4754
try:
4855
UUID(u)
4956
except ValueError:

0 commit comments

Comments
 (0)