Skip to content

Commit 6c7a1c5

Browse files
committed
gh-125651: Fix UUID hex parsing with underscores
1 parent 0cb20f2 commit 6c7a1c5

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

Lib/test/test_uuid.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ def test_exceptions(self):
232232
# Badly formed hex strings.
233233
badvalue(lambda: self.uuid.UUID(''))
234234
badvalue(lambda: self.uuid.UUID('abc'))
235+
badvalue(lambda: self.uuid.UUID("123_4567812345678123456781234567"))
236+
badvalue(lambda: self.uuid.UUID("123_4567812345678123456781_23456"))
235237
badvalue(lambda: self.uuid.UUID('1234567812345678123456781234567'))
236238
badvalue(lambda: self.uuid.UUID('123456781234567812345678123456789'))
237239
badvalue(lambda: self.uuid.UUID('123456781234567812345678z2345678'))

Lib/uuid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
176176
'or int arguments must be given')
177177
if hex is not None:
178178
hex = hex.replace('urn:', '').replace('uuid:', '')
179-
hex = hex.strip('{}').replace('-', '')
179+
hex = hex.strip("{}").replace("-", "").replace("_", "")
180180
if len(hex) != 32:
181181
raise ValueError('badly formed hexadecimal UUID string')
182182
int = int_(hex, 16)

0 commit comments

Comments
 (0)