Skip to content

fix: prefer suffixed locales to avoid Perl 5.42.0 panic (GH #448)#450

Draft
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-date-locale-panic
Draft

fix: prefer suffixed locales to avoid Perl 5.42.0 panic (GH #448)#450
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-date-locale-panic

Conversation

@toddr-bot

@toddr-bot toddr-bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

What

Prefer suffixed locale names (e.g. en_GB.UTF-8) over bare names (e.g. en_GB) when probing locale availability in Template::Plugin::Date.

Why

Perl 5.42.0 introduced a fatal panic in locale.c when nl_langinfo(CODESET) returns empty for a locale that setlocale() accepted. On macOS, bare locale names like en_GB lack a codeset, so setlocale(LC_ALL, "en_GB") succeeds but subsequent strftime() panics because Perl internally queries the codeset.

Reproducer (no Template modules needed):

perl -MPOSIX -e 'setlocale(LC_ALL, "en_GB") and print strftime("%A", localtime)'

See #448 for full analysis.

How

Two changes to the locale probe loop in Date.pm:

  1. Try suffixed locales first, bare last: for my $suffix (@LOCALE_SUFFIX, '') instead of ('', @LOCALE_SUFFIX). On macOS, en_GB.UTF-8 matches before the bare en_GB, avoiding the panic.

  2. Reorder @LOCALE_SUFFIX: .UTF-8 moved to front since it's the most common modern encoding. Previous order was .ISO8859-1 first (historical).

Both changes are backwards compatible — if only bare locale names exist on a system, the fallback at the end of the loop still finds them.

The mirror loop in t/date.t is updated to match.

Testing

  • t/date.t passes
  • Full test suite passes (make test)
  • The actual panic requires Perl 5.42.0 + macOS to reproduce

Closes #448


Quality Report

Changes: 2 files changed, 3 insertions(+), 3 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan

Perl 5.42.0 panics when nl_langinfo(CODESET) returns empty for a
locale that setlocale() accepted. On macOS, bare locale names like
'en_GB' trigger this because they lack a codeset suffix.

Fix by trying suffixed locales (.UTF-8, etc.) before bare names in
the locale probe loop. Also reorder @LOCALE_SUFFIX to try .UTF-8
first since it is the most common modern encoding.
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.

t/date.t panics on Perl 5.42.0 Darwin: nl_langinfo locale codeset empty

1 participant