Skip to content

Conversation

troysis
Copy link

@troysis troysis commented Sep 30, 2025

Type of changes

  • [ x ] Bug fix
  • New feature
  • Documentation / docstrings
  • [ x ] Tests
  • Other

Checklist

  • [ x ] I've run the latest black with default args on new code.
  • I've updated CHANGELOG.md and CONTRIBUTORS.md where appropriate.
  • [ x ] I've added tests for new code.
  • [ x ] I accept that @willmcgugan may be pedantic in the code review.

Description

Summary
Fixes false positives where ReprHighlighter highlighted embedded 0x… (e.g., 1920x1080). Tightens the regex to match standalone hex literals only, while supporting optional sign, uppercase 0X, and single underscore separators between digits.

Related issue
Fixes #3854

Regex

(?<![0-9A-Za-z_])[+-]?0[xX]0-9A-Fa-f*(?![0-9A-Za-z_])

Changes

rich/highlighter.py: updated hex branch in ReprHighlighter.

tests/test_highlighter.py: added expanded boundary cases (signs, 0X, underscores, punctuation boundaries, invalid underscores).

QA

Focused + full tests: pytest -q

Tooling: black, ruff, mypy clean on touched files

Scope

Scoped to ReprHighlighter; JSON highlighter unchanged.

@troysis
Copy link
Author

troysis commented Sep 30, 2025

Thanks for reviewing this!

This PR fixes false positives where ReprHighlighter highlighted embedded 0x… (e.g., 1920x1080).
I limited the change to ReprHighlighter only (JSON unchanged) and added boundary tests.

The current regex supports:

optional +/- sign

uppercase 0X as well as lowercase

single underscores between digits (PEP 515 style), while forbidding double/trailing underscores

If you’d prefer a simpler version (e.g., just boundary + 0X support without underscores), I’m happy to adjust quickly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] "0x1080" is highlighted in "1920x1080". Need a word boundary for "0x" pattern

1 participant