-
Notifications
You must be signed in to change notification settings - Fork 504
Added error handling and safe indexing to score_fuzzy algorithm #516
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
base: main
Are you sure you want to change the base?
Conversation
Improved the `score_fuzzy` algorithm by introducing essential error handling and input validation while preserving the original logic and comments. Specifically, early returns have been added for empty strings or impossible match scenarios to prevent unnecessary computation. Matrix size calculations now use `.checked_mul()` to avoid potential overflow errors. Access to previous characters in the target string uses `.get()` with safe bounds checking to prevent panics, and contiguous match checks employ `.map_or(false, ...)` to handle edge cases safely.
@GiorgosTsak please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...otherwise LGTM!
src/fuzzy.rs
Outdated
if needle.len() > haystack.len() { | ||
// impossible for query to be contained in target | ||
return (NO_MATCH, Vec::new_in(arena)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this check is wrong, because after mapping, the needle may be shorter than before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes you are probably correct, this could produce false negatives. I will change it.
Removed the unnecessary check on the 26-29 lines.
Are you sure you tested this PR locally? If you don't mind me saying, the lack of running rustfmt, and the commit titles that are rather typical for the online GitHub code editor, indicate you didn't. |
Improved the
score_fuzzy
algorithm by introducing essential error handling and input validation while preserving the original logic and comments. Specifically, early returns have been added for empty strings or impossible match scenarios to prevent unnecessary computation. Matrix size calculations now use.checked_mul()
to avoid potential overflow errors. Access to previous characters in the target string uses.get()
with safe bounds checking to prevent panics, and contiguous match checks employ.map_or(false, ...)
to handle edge cases safely.