Skip to content

fix: handle character boundary in search mode #18928

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

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

roife
Copy link
Member

@roife roife commented Jan 12, 2025

fix #18918

I also used Clippy to scan and check usages of slicing in the project, and found that only here could cause a panic.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 12, 2025
@ChayimFriedman2
Copy link
Contributor

There is another slicing that looks like it may panic in line 305 (let prefix = &candidate[..query.len()];).

But do you know why it panics? We use match_indices(), it should return a correct index.

@Veykril
Copy link
Member

Veykril commented Jan 15, 2025

But do you know why it panics? We use match_indices(), it should return a correct index.

We panic because we slice one byte after the character, so if the character is multi byte we slice into it instead of beyond it.

There is another slicing that looks like it may panic in line 305 (let prefix = &candidate[..query.len()];).

That one shouldn't cause issues, given the searcher in that mode does a prefix search and so the prefix should match fully (it would be a bug if not)

@ChayimFriedman2
Copy link
Contributor

There is another slicing that looks like it may panic in line 305 (let prefix = &candidate[..query.len()];).

That one shouldn't cause issues, given the searcher in that mode does a prefix search and so the prefix should match fully (it would be a bug if not)

But it might not match.

@Veykril
Copy link
Member

Veykril commented Jan 15, 2025

Then we shouldn't even reach that far, the fst automaton should only give us prefix matches, the only thing that can differ at that point is the ascii casing which will not cause issues here. (if we were doing general casing changes it might)

@Veykril Veykril enabled auto-merge February 12, 2025 13:53
@Veykril Veykril added this pull request to the merge queue Feb 12, 2025
Merged via the queue into rust-lang:master with commit 12d8725 Feb 12, 2025
9 checks passed
@roife roife deleted the fix-18918 branch April 15, 2025 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug Report: Panic When Using Japanese Function Names in Rust Analyzer(boundary issue)
4 participants