python / python/cpython

UUID wrongly parses hex values with underscores

Open
#125,651 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Bug description:
import uuid
uuid.UUID("123_4567812345678123456781234567")
#  UUID('01234567-8123-4567-8123-456781234567')

UUID parsing hex strings internally uses int method which from Python 3.6 accepts underscores (_) as digit separators

Changed in version 3.6: Grouping digits with underscores as in code literals is allowed.

Since the UUID does not performs sanitization of this character this may result in parsing as valid non-RFC compliant UUID values.

CPython versions tested on:

3.10, CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-125652

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the uuid.UUID parsing path shown in the report and inspect where the input is passed to int. Confirm the behavior with the example value; done means hexadecimal strings containing underscores are rejected or otherwise no longer parsed into a valid UUID, with coverage for this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.