fix: Panic in unicode boundary checking code #578
No reviewers
Labels
No labels
Compat/Breaking
Kind
Bad merge
Kind
Bug
Kind
Documentation
Kind
Enhancement
Kind
Feature
Kind
New language
Kind
Security
Kind
Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: mergiraf/mergiraf#578
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "wetneb/string_boundary_panic"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Since the full length of the string is a valid unicode boundary,
the range of lengths to check needs to end with the "len + 1" excluded
upper bound.
863e51d2ac
toebe7a7b21a
Note that Rust's implementation is quite different, I wonder if it would make sense to just copy it?
https://doc.rust-lang.org/src/core/str/mod.rs.html#446
Yeah, it does some shenanigans to avoid bounds checks and the like -- definitely the right decision for an std function, but I decided to keep it dead simple for our use case (yet still managed to make a mistake 🤦♀️)
The feature that implements this function has already been stabilized, so I'd say we just wait for Rust 1.91.0..
well that's embarrassing.. thank you for noticing this^^
@ -35,3 +35,3 @@
len
} else {
(index..len)
(index..(len + 1))
nit:
index..=len
is imo a bit more readable@ -43,0 +43,4 @@
#[cfg(test)]
mod test {
use crate::StrExt;
nit: replacing this with
use super::*
is probably more future-proof..@ -43,0 +47,4 @@
#[allow(unstable_name_collisions)]
#[test]
fn char_boundary_at_end() {
thank you for actually adding a test for this:)