diff --git a/crates/proof/src/hyphen.rs b/crates/proof/src/hyphen.rs index 8caf05c6dd..45f8118051 100644 --- a/crates/proof/src/hyphen.rs +++ b/crates/proof/src/hyphen.rs @@ -242,9 +242,10 @@ fn composed_chars(core: &[char]) -> (Vec, Vec>) { (nfc, starts) } -/// Does a pack's `pats` hyphenate `core` in `lang`? Russian, Bulgarian, Turkish and Gujarati: a -/// word in their script (the guard their rules use) whose letters the patterns know, so a word with a -/// letter the pack never mentions goes on to the fallback rules. Polish, Portuguese, Italian +/// Does a pack's `pats` hyphenate `core` in `lang`? Russian, Bulgarian, Turkish, Gujarati and +/// Hindi: a word in their script (the guard their rules use; for Gujarati and Hindi, the script's +/// letters and marks and the joiners inside a conjunct, [`crate::indic`]) whose letters the +/// patterns know, so a word with a letter the pack never mentions goes on to the fallback rules. Polish, Portuguese, Italian /// and German: every word, as their embedded patterns do. Any other language: a word whose letters /// the patterns know. fn pack_patterns_fit(lang: ProofLang, pats: &Patterns, core: &[char]) -> bool { @@ -253,7 +254,9 @@ fn pack_patterns_fit(lang: ProofLang, pats: &Patterns, core: &[char]) -> bool { ProofLang::Bg => core.iter().all(|&c| crate::bg::is_letter(c)) && pack_knows(pats, core), ProofLang::Tr => core.iter().all(|&c| crate::tr::hyphen::is_letter(c)) && pack_knows(pats, core), ProofLang::Pl | ProofLang::Pt | ProofLang::It | ProofLang::De => true, - ProofLang::Gu => core.iter().all(|&c| crate::gu::is_gujarati_char(c)) && pack_knows(pats, core), + ProofLang::Gu | ProofLang::Hi => { + crate::indic::Script::of(lang).is_some_and(|s| core.iter().all(|&c| s.is_letter(c))) && pack_knows(pats, core) + } _ => pats.values(core).is_some(), } } diff --git a/crates/proof/src/hyphen/tests.rs b/crates/proof/src/hyphen/tests.rs index d4a8c8117e..26705716e7 100644 --- a/crates/proof/src/hyphen/tests.rs +++ b/crates/proof/src/hyphen/tests.rs @@ -195,6 +195,18 @@ fn gujarati_pack_patterns_fit_checks_script_and_exceptions() { assert!(!pack_patterns_fit(ProofLang::Gu, &pats, &en_word)); } +/// CodeRabbit on craft-libs#3905: a word with a joiner in a conjunct still reaches its pack's +/// exception word (here: no break at all), in Gujarati and Hindi. +#[test] +fn indic_pack_exceptions_reach_words_with_joiners() { + for (lang, word) in [(ProofLang::Gu, "પુસ્\u{200D}તક"), (ProofLang::Hi, "पुस्\u{200D}तक")] { + let pats = Patterns::parse(&format!("1ક 1क \\hyphenation{{{word}}}")); + let core: Vec = word.chars().collect(); + assert!(pack_patterns_fit(lang, &pats, &core), "{lang:?}"); + assert_eq!(core_breaks_patterns(&pats, &core), (vec![], Source::Dictionary), "{lang:?}"); + } +} + /// storytold/vectorcraft#4947: Gujarati text breaks between aksharas, within the paragraph's /// limits, where it used to fall to the English rules and get no break at all; a Latin word in /// a Gujarati run is still hyphenated as English.