Fix UTF-8 handling for strftime format strings - #2080
Draft
designet-inc-oss wants to merge 1 commit into
Draft
Conversation
## Summary
On AlmaLinux 10, Japanese characters in format strings passed to `POSIX::strftime()` are handled differently from AlmaLinux 9.
When a Japanese character is included in the format string, `strftime()` can return a string with the UTF-8 flag enabled while the underlying data is still UTF-8 encoded bytes.
This can cause Japanese characters to become garbled when `Encode::_utf8_off()` is subsequently called.
## Change
Decode the format string as UTF-8 before passing it to `POSIX::strftime()`.
```perl
$format = $self->gettext($format);
$format = Encode::decode('UTF-8', $format);
```
## Verification
The behavior was reproduced on AlmaLinux 10 using a format string containing Japanese characters.
Before this change, the following behavior was observed:
```text
format:
UTF8 flag = OFF
bytes = 30.E5.B9.B4.30
after strftime():
UTF8 flag = ON
bytes = 30.E5.B9.B4.30
after Encode::_utf8_off():
0å¹´0
```
After decoding the format string before calling `strftime()`:
```text
format:
UTF8 flag = ON
Unicode character U+5E74
after strftime():
UTF8 flag = ON
Unicode character U+5E74
after Encode::_utf8_off():
0年0
```
The same test on AlmaLinux 9 produces the expected Unicode string from `strftime()` without this additional conversion.
This change makes the format string explicitly a Unicode string before it is passed to `strftime()`, and prevents the character encoding mismatch observed on AlmaLinux 10.
## Scope
This change only adds UTF-8 decoding of the localized format string before the existing `strftime()` processing.
Member
|
@designet-inc-oss ,
|
Author
|
それぞれの環境に入っているバージョンは以下になります。 AlmaLinux 9.8 AlmaLinux10.2 |
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.
Summary
On AlmaLinux 10, Japanese characters in format strings passed to
POSIX::strftime()are handled differently from AlmaLinux 9.When a Japanese character is included in the format string,
strftime()can return a string with the UTF-8 flag enabled while the underlying data is still UTF-8 encoded bytes.This can cause Japanese characters to become garbled when
Encode::_utf8_off()is subsequently called.Change
Decode the format string as UTF-8 before passing it to
POSIX::strftime().Verification
The behavior was reproduced on AlmaLinux 10 using a format string containing Japanese characters.
Before this change, the following behavior was observed:
After decoding the format string before calling
strftime():The same test on AlmaLinux 9 produces the expected Unicode string from
strftime()without this additional conversion.This change makes the format string explicitly a Unicode string before it is passed to
strftime(), and prevents the character encoding mismatch observed on AlmaLinux 10.Scope
This change only adds UTF-8 decoding of the localized format string before the existing
strftime()processing.