fix: remove use locale from Filters.pm for Unicode correctness (GH #137)#386
Draft
toddr-bot wants to merge 1 commit intoabw:masterfrom
Draft
fix: remove use locale from Filters.pm for Unicode correctness (GH #137)#386toddr-bot wants to merge 1 commit intoabw:masterfrom
toddr-bot wants to merge 1 commit intoabw:masterfrom
Conversation
…w#137) The `use locale` pragma in Filters.pm caused wide character warnings when processing strings with codepoints > 255 through case-changing filters (upper, lower, ucfirst, lcfirst). It also made uc/lc operate on bytes rather than characters for non-ASCII strings. Fix: remove `use locale` and use `utf8::upgrade` in the case filters to ensure Perl applies Unicode case folding rules regardless of the string's internal storage format. Closes abw#137 Co-Authored-By: Kōan <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Remove
use localefrom Template::Filters and addutf8::upgradeto the case-changing filter functions (upper,lower,ucfirst,lcfirst).Why
The
use localepragma (added in 2006) causesuc/lcto operate on bytes rather than Unicode characters. When processing strings with codepoints > U+00FF (e.g. Cyrillic, CJK), this producesWide character in substitutionwarnings and can silently corrupt output. Reported in #137.How
use localefrom Filters.pm. No other code in the module depends on locale-sensitive behavior (\s+and\d+patterns used intrim/collapse/indentare locale-invariant).utf8::upgradein the four case filters to ensure Perl applies Unicode case folding rules even for Latin-1 range characters (0x80-0xFF) that might be stored as bytes internally.utf8::upgradefunction is available since Perl 5.8 (the project's minimum version), so no compatibility issues.Testing
t/unicode_filters.twith 10 tests: Latin-1 case folding (upper/lower/ucfirst/lcfirst), Cyrillic wide characters (upper/lower + no-warnings check), and ASCII regression tests.Closes #137
Quality Report
Changes: 2 files changed, 121 insertions(+), 5 deletions(-)
Code scan: clean
Tests: passed (OK)
Branch hygiene: clean
Generated by Kōan post-mission quality pipeline