Skip to content

fix: respect Blacklist/Whitelist options for single-language scripts#30

Open
Yanhu007 wants to merge 1 commit into
abadojack:masterfrom
Yanhu007:fix/options-check-single-lang-scripts
Open

fix: respect Blacklist/Whitelist options for single-language scripts#30
Yanhu007 wants to merge 1 commit into
abadojack:masterfrom
Yanhu007:fix/options-check-single-lang-scripts

Conversation

@Yanhu007

Copy link
Copy Markdown

Fixes #28

Problem

Languages detected by unique script (Han→Mandarin, Bengali→Bengali, Hangul→Korean, etc.) bypassed Options entirely. Blacklist and Whitelist were only checked for multi-language scripts (Latin, Cyrillic, etc.) that go through detectLangInProfiles.

opts := Options{Blacklist: map[Lang]bool{Cmn: true}}
info := DetectWithOptions("你好世界", opts)
// Expected: lang=unknown (blacklisted)
// Got:      lang=Mandarin, confidence=1.0 (blacklist ignored!)

Fix

Add filterLangByOptions helper that checks Blacklist/Whitelist before returning single-language script detections. If the language is filtered out, returns (-1, 0) (unknown).

Testing

All existing tests pass. Manually verified:

  • Chinese text with Cmn blacklisted → returns unknown ✅
  • Chinese text with Japanese-only whitelist → returns unknown ✅
  • Chinese text without options → returns Mandarin ✅

Languages detected by script alone (Han, Bengali, Hangul, etc.)
bypassed the Options check entirely, ignoring both Blacklist and
Whitelist. Only multi-language scripts (Latin, Cyrillic, etc.)
went through detectLangInProfiles which checks options.

Add filterLangByOptions helper that validates single-language
script detections against Blacklist/Whitelist before returning.

Fixes abadojack#28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The "Options" does not work WHEN the detected script is not in (Latin,Cyrillic,Devanagari,Hebrew,Ethiopic,Arabic)

1 participant