Offline, privacy-first grammar checker. Fast, open-source, Rust-powered
fix: prevent crash in PhrasalVerbAsCompoundNoun (#1210)
Michael Schmidt4636081f6209
diff --git a/harper-core/src/linting/phrasal_verb_as_compound_noun.rs b/harper-core/src/linting/phrasal_verb_as_compound_noun.rsindex 5ba4e7b6e..601252037 100644--- a/harper-core/src/linting/phrasal_verb_as_compound_noun.rs+++ b/harper-core/src/linting/phrasal_verb_as_compound_noun.rs@@ -47,27 +47,25 @@ impl Linter for PhrasalVerbAsCompoundNoun {continue;}let nountok_charsl = document.get_span_content(&token.span);- // * Can't contain a hyphen or space.- if nountok_charsl.contains(&'-') || nountok_charsl.contains(&' ') {- // This means Harper's tokenizer's concept of a word is different to what we expect- // or has changed since this code was written.- unreachable!();- }- // * Can't contain an apostrophe- if nountok_charsl.contains(&'\'') || nountok_charsl.contains(&'’') {+ // * Can't contain space, hyphen or apostrophe+ if nountok_charsl.contains(&' ')+ || nountok_charsl.contains(&'-')+ || nountok_charsl.contains(&'\'')+ || nountok_charsl.contains(&'’')+ {continue;}// * Must end with the same letters as one of the particles used in phrasal verbs.let particle_endings: &[&[char]] = &[- &['a', 'r', 'o', 'u', 'n', 'd'][..],- &['b', 'a', 'c', 'k'][..],- &['d', 'o', 'w', 'n'][..],- &['i', 'n'][..],- &['o', 'n'][..],- &['o', 'f', 'f'][..],- &['o', 'u', 't'][..],- &['o', 'v', 'e', 'r'][..],- &['u', 'p'][..],+ &['a', 'r', 'o', 'u', 'n', 'd'],+ &['b', 'a', 'c', 'k'],+ &['d', 'o', 'w', 'n'],+ &['i', 'n'],+ &['o', 'n'],+ &['o', 'f', 'f'],+ &['o', 'u', 't'],+ &['o', 'v', 'e', 'r'],+ &['u', 'p'],];// * Must not be in the set of known false positives.@@ -371,4 +369,13 @@ mod tests {0,);}++ #[test]+ fn ignore_multi_word() {+ assert_lint_count(+ "I like this add-on!",+ PhrasalVerbAsCompoundNoun::default(),+ 0,+ );+ }}