Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix range bugs in str substring and str index-of #14863

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Bahex
Copy link
Contributor

@Bahex Bahex commented Jan 19, 2025

Description

  • implement FromValue for IntRange, as it is very common to use integer ranges as arguments
  • IntRange::absolute_start can now point one-past-end
  • IntRange::absolute_end converts relative Included bounds to absolute Excluded bounds
  • IntRange::absolute_bounds is convenience method that calls the other absolute_* method and transforms reverse ranges to empty at start (5..3 => 5..<5)
  • refactored str substring tests to allow empty exclusive range tests
  • fix the 0..<0 case for str substring and str index-of

User-Facing Changes

There should be no noticeable changes other than the bugfix.

Tests + Formatting

  • 🟢 toolkit fmt
  • 🟢 toolkit clippy
  • 🟢 toolkit test
  • 🟢 toolkit test stdlib

After Submitting

N/A

Bahex added 7 commits January 18, 2025 09:37
A lot of commands that accept range arguments specifically need
IntRange, this reduces the required boilerplate.
`process_range` returns inclusive bounds, which were used as if they
were end-exclusive resulting in an off-by-one

start bound cast to usize without handling negative values, causing and
underflow and resulting in an out of bounds access.
absolute_start_new and absolute_end_new are an implementation detail
that will hopefully be folded into existing functions
- fix 0..<0 case
- the previous impl's grapheme handling might have been broken in some
  cases, I didn't confirm this hunch but the new impl is easier to
  follow and no tests broke
@WindSoilder WindSoilder mentioned this pull request Jan 19, 2025
@Bahex Bahex marked this pull request as draft January 19, 2025 18:13
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.

Range slicing operations return whole value instead of empty list when using range 0..<0
1 participant