Skip to content

Fix potential index out of range in LineIndex computation#25492

Merged
MichaReiser merged 2 commits into
astral-sh:mainfrom
fallintoplace:fix-line-end-exclusive-crlf
Jun 1, 2026
Merged

Fix potential index out of range in LineIndex computation#25492
MichaReiser merged 2 commits into
astral-sh:mainfrom
fallintoplace:fix-line-end-exclusive-crlf

Conversation

@fallintoplace

Copy link
Copy Markdown
Contributor

Summary

LineIndex::line_end_exclusive always subtracts one byte from the start of the next line. That works for \n and \r, but it returns the wrong offset for \r\n line endings.

This updates the helper to subtract the full line-ending width and adds unit tests covering LF, CRLF, and CR inputs.

Test Plan

  • cargo fmt -p ruff_source_file --check
  • cargo test -p ruff_source_file

@fallintoplace fallintoplace marked this pull request as ready for review May 30, 2026 20:00
@astral-sh-bot

astral-sh-bot Bot commented May 30, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@MichaReiser MichaReiser added bug Something isn't working internal An internal refactor or improvement labels Jun 1, 2026
@MichaReiser MichaReiser changed the title Fix LineIndex::line_end_exclusive for CRLF line endings Fix potential index out of range in LineIndex computation Jun 1, 2026
@MichaReiser MichaReiser enabled auto-merge (squash) June 1, 2026 06:58
@MichaReiser MichaReiser disabled auto-merge June 1, 2026 07:01
@MichaReiser MichaReiser merged commit 88d8514 into astral-sh:main Jun 1, 2026
50 checks passed
carljm added a commit that referenced this pull request Jun 1, 2026
* main:
  [`pydocstyle`] Improve discoverability of rules enabled for each convention (#24973)
  [ty] Deduplicate retained use-def place states (#25450)
  [ty] reduce features of low-level crates depended on by `ty_python_semantic` (#25524)
  [ty] Fix narrowing enum literal unions by member identity (#25520)
  [ty] Test tagged union narrowing for named tuples (#25519)
  [ty] Disallow file-system access in `ty_python_core` (#25518)
  [ty] Nominal Tagged Union Narrowing (#24916)
  Commit `scripts/uv.lock` (#25517)
  Fix potential index out of range in `LineIndex` computation (#25492)
  [ty] Sync vendored typeshed stubs (#25514)
  [ty] Add disjointness for protocol method members (#25315)
  [ty] Use compact sets for more immutable fields (#25476)
  [ty] Derive `Default` for `FunctionDecoratorInference` (#25482)
  [ty] Ignore rejected assignments for synthesized bindings (#25340)
  [ty] Handle cycles in function decorator inference (#25475)
  docs: fix typo `bin/active` → `bin/activate` in tutorial (#25473)
  [ty] Narrow bound method overloads by receiver (#24707)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working internal An internal refactor or improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants