Skip to content

Commit

Permalink
pythongh-125651: Fix UUID hex parsing with underscores
Browse files Browse the repository at this point in the history
  • Loading branch information
sevdog committed Oct 17, 2024
1 parent 0cb20f2 commit 6c7a1c5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Lib/test/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ def test_exceptions(self):
# Badly formed hex strings.
badvalue(lambda: self.uuid.UUID(''))
badvalue(lambda: self.uuid.UUID('abc'))
badvalue(lambda: self.uuid.UUID("123_4567812345678123456781234567"))
badvalue(lambda: self.uuid.UUID("123_4567812345678123456781_23456"))
badvalue(lambda: self.uuid.UUID('1234567812345678123456781234567'))
badvalue(lambda: self.uuid.UUID('123456781234567812345678123456789'))
badvalue(lambda: self.uuid.UUID('123456781234567812345678z2345678'))
Expand Down
2 changes: 1 addition & 1 deletion Lib/uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None,
'or int arguments must be given')
if hex is not None:
hex = hex.replace('urn:', '').replace('uuid:', '')
hex = hex.strip('{}').replace('-', '')
hex = hex.strip("{}").replace("-", "").replace("_", "")
if len(hex) != 32:
raise ValueError('badly formed hexadecimal UUID string')
int = int_(hex, 16)
Expand Down

0 comments on commit 6c7a1c5

Please sign in to comment.