Skip to content

String ending with octal causes panic when UP012 selected #24389

@stefanomoro

Description

@stefanomoro

Ruff panics on a valid Python file containing this line:

IMR_HEADER = "$IMURAW\0".encode("ascii")

File to reproduce it

# SPDX-FileCopyrightText: Aresys S.r.l. <info@aresys.it>
# SPDX-License-Identifier: MIT

"""Test."""

IMR_HEADER = "$IMURAW\0".encode("ascii")

Command used
python -m ruff check tmp_repro.py

Observed output:

1:1 panic: Panicked at crates/ruff_python_trivia/src/cursor.rs:170:41 ...
byte index 1 is out of bounds ...

Ruff version:
ruff 0.15.9

This is valid Python and runs correctly. Replacing it with:

IMR_HEADER = b"$IMURAW\x00"

works around the issue.

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions