Repository navigation
[FIX] --sentencecap, --capfile, --kf, --profanity-file miss most words (word lists never sorted) - #2397
Open
Deepak-negi11 wants to merge 1 commit into
Open
[FIX] --sentencecap, --capfile, --kf, --profanity-file miss most words (word lists never sorted)#2397Deepak-negi11 wants to merge 1 commit into
Deepak-negi11 wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In raising this pull request, I confirm the following (please check boxes):
Reason for this PR:
Sanity check:
Repro instructions:
Sample SCC file with these four captions: "I LIKE JUNE AND MONDAY.", "SEE YOU IN JANUARY.", "WHAT THE SHIT IS THIS.", "HELLO WORLD, ZONK BLURG." (I can attach it).
words.txtcontainsWoRlDandHeLLo;bad.txtcontainszonkandblurg.--sentencecap--capfile words.txt--profanity-file bad.txtProblem
The C encoders look words up with
bsearch()andstrcasecmp(ccx_encoders_helpers.c), which needs the lists sorted the same way. The old C parser sorted them withccx_encoders_helpers_perform_shellsort_words(). The Rust parser builds the lists (built-in words, then the user's file) but never sorts them, and nothing calls that function anymore. So most words are missed, depending on where they land in the list.Fix
Sort both lists in
parse_parameters()right after they're built, instrcasecmporder (byte-wise, ASCII-lowercased).Testing
strcasecmp(including_, which sorts differently with lowercase vs uppercase comparison).--sentencecapand--kflists is found by binary search, asbsearchdoes. Fails on master.cargo test(428 passed),cargo fmt --check,cargo clippy -- -D warnings.