Skip to content

Commit bcac51f

Browse files
committed
gh-125651: Fix UUID hex parsing with underscores
1 parent c72ffe7 commit bcac51f

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
@@ -277,6 +277,8 @@ def test_exceptions(self):
277277
# Badly formed hex strings.
278278
badvalue(lambda: self.uuid.UUID(''))
279279
badvalue(lambda: self.uuid.UUID('abc'))
280+
badvalue(lambda: self.uuid.UUID("123_4567812345678123456781234567"))
281+
badvalue(lambda: self.uuid.UUID("123_4567812345678123456781_23456"))
280282
badvalue(lambda: self.uuid.UUID('1234567812345678123456781234567'))
281283
badvalue(lambda: self.uuid.UUID('123456781234567812345678123456789'))
282284
badvalue(lambda: self.uuid.UUID('123456781234567812345678z2345678'))

Lib/uuid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
214214
pass
215215
elif hex is not None:
216216
hex = hex.replace('urn:', '').replace('uuid:', '')
217-
hex = hex.strip('{}').replace('-', '')
217+
hex = hex.strip("{}").replace("-", "").replace("_", "")
218218
if len(hex) != 32:
219219
raise ValueError('badly formed hexadecimal UUID string')
220220
int = int_(hex, 16)

0 commit comments

Comments
 (0)