Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

fix(core): DisjointPrefixes keeps title case when joining prefix (#4641)

Pujitha Paladugud8432a5c83b5
diff --git a/harper-core/src/linting/disjoint_prefixes.rs b/harper-core/src/linting/disjoint_prefixes.rs
index 43fe31c2b..226eaae0e 100644
--- a/harper-core/src/linting/disjoint_prefixes.rs
+++ b/harper-core/src/linting/disjoint_prefixes.rs
@@ -121,7 +121,8 @@ impl<D: Dictionary> ExprLinter for DisjointPrefixes<D> {
let suggestions = suggestions
.iter()
.map(|s| {
- Suggestion::replace_with_match_case(s.chars().collect(), toks_span.get_content(src))
+ // Copy casing from the prefix alone, so "Pre-Requisite" becomes "Prerequisite", not "PreRequisite"
+ Suggestion::replace_with_match_case(s.chars().collect(), toks[0].get_ch(src))
})
.collect();
@@ -214,4 +215,22 @@ mod tests {
DisjointPrefixes::new(FstDictionary::curated()),
);
}
+
+ #[test]
+ fn fix_title_case_hyphenated_to_joined_4381() {
+ assert_suggestion_result(
+ "Pre-Requisite",
+ DisjointPrefixes::new(FstDictionary::curated()),
+ "Prerequisite",
+ );
+ }
+
+ #[test]
+ fn fix_all_caps_hyphenated_to_joined() {
+ assert_suggestion_result(
+ "PRE-REQUISITE",
+ DisjointPrefixes::new(FstDictionary::curated()),
+ "PREREQUISITE",
+ );
+ }
}