oscerd opened a new pull request, #26067:
URL: https://github.com/apache/camel/pull/26067

   ## Issue
   [CAMEL-24608](https://issues.apache.org/jira/browse/CAMEL-24608)
   
   ## Problem
   `LanguageGuardrail` declares `minLanguageRatio`, sets it from the 
constructor and the builder method
   `minLanguageRatio(double)`, and stores it — but `validate()` never reads it 
(and there was no getter).
   A user who configures `minLanguageRatio(0.8)` expects at least 80% of the 
characters to be in an allowed
   language; the ratio was silently ignored, so text that is mostly a foreign 
script with a single
   allowed-language character still passed.
   
   ## Fix
   Enforce the ratio in `validate()`: compute the fraction of non-whitespace 
characters that belong to at
   least one allowed language/script and fail when it is below 
`minLanguageRatio`. The check is a no-op at
   the default `0.0`. Also add the missing `getMinLanguageRatio()` getter.
   
   Note: the ratio is meaningful for the per-character script languages 
(LATIN_SCRIPT, CYRILLIC, CHINESE, …).
   `ENGLISH` uses a whole-string ASCII pattern, so a message that reaches the 
ratio check under
   `allowedLanguages={ENGLISH}` is already all-ASCII (ratio 1.0) — consistent 
with the existing detection.
   
   ## Testing
   - New `testMinLanguageRatioIsEnforced` asserts a mostly-CJK message with 
`LATIN_SCRIPT` allowed and
     `minLanguageRatio(0.8)` is rejected, while all-Latin text passes. All 
existing `LanguageGuardrailTest`
     cases still pass.
   - `mvn -Psourcecheck validate` green.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   
   https://claude.ai/code/session_01Ka4dAcJMpxahMfk3kmG5Ls


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to