From a8b653dc97461f64f3832199324112430252936c Mon Sep 17 00:00:00 2001 From: Robert Mongold Date: Tue, 27 Oct 2026 22:38:19 -0400 Subject: [PATCH 1/3] Make is_correct require a single real word --- src/lib.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index b79d27c..dd3a8ba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -218,8 +218,28 @@ impl Checker { self.0.check(text).map(SpellingError) } - /// Returns true if `word` is spelled correctly. + /// Returns true if `word` is a single spelled-correctly token. + /// + /// The input is trimmed. It must be exactly one whitespace-delimited token + /// that contains at least one letter or digit. Otherwise this returns + /// `false` (empty input, `"!!!"`, `"hello world"`, etc.). pub fn is_correct(&self, word: &str) -> bool { + let word = word.trim(); + if word.is_empty() { + return false; + } + + let mut tokens = word.split_whitespace(); + let Some(token) = tokens.next() else { + return false; + }; + if tokens.next().is_some() { + return false; + } + if !token.chars().any(|c| c.is_alphanumeric()) { + return false; + } + self.check(word).next().is_none() } From d71a1577dee82aa012a2544b42d01302367fdf61 Mon Sep 17 00:00:00 2001 From: Robert Mongold Date: Tue, 27 Oct 2026 22:38:44 -0400 Subject: [PATCH 2/3] Add tests --- src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index dd3a8ba..7b22862 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -560,6 +560,11 @@ mod tests { let checker = Checker::with_locale("en_US").unwrap(); assert!(checker.is_correct("believe")); assert!(!checker.is_correct("beleeve")); + assert!(!checker.is_correct("")); + assert!(!checker.is_correct(" ")); + assert!(!checker.is_correct("!!!")); + assert!(!checker.is_correct("hello world")); + assert!(checker.is_correct(" believe ")); } #[test] From 8728535c855a2bc2346950f529a127310f61fe5c Mon Sep 17 00:00:00 2001 From: Robert Mongold Date: Tue, 27 Oct 2026 22:38:57 -0400 Subject: [PATCH 3/3] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1894b78..8854d6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ This project follows [Semantic Versioning](https://semver.org/). - `with_locale("en")` tries `en`, then `en_US`, then `en_GB` - macOS `with_locale` stores the installed language tag that matched, and accepts a bare language when only a regional tag is installed - Linux tokenization uses Hunspell `WORDCHARS`/`ICONV`, keeps curly apostrophes in words, trims edge quotes, and skips URLs and emails +- `is_correct` requires a single whitespace-delimited token with a letter or digit; empty and punctuation-only inputs are false ## [0.4.0] - 2026-08-25