Skip to content

ofToLower / ofToUpper: use a UTF-8 locale when the environment has none - #8593

Open
danoli3 wants to merge 1 commit into
openframeworks:masterfrom
danoli3:locale-utf8-fallback
Open

danoli3 wants to merge 1 commit into
openframeworks:masterfrom
danoli3:locale-utf8-fallback

Conversation

@danoli3

@danoli3 danoli3 commented Oct 18, 2026

Copy link
Copy Markdown
Member

ofToLower / ofToUpper (and the other getLocale() users) take the environment's locale when no locale is passed. With LANG unset (Docker images, chroots, some services) that is C, which only maps ASCII case:

ofToLower("AbCéÉBbCcc")  ->  "abcéÉbbccc"   (expected "abcéébbccc")

This failed tests/utils/strings (tolower, toupper) when testing #8540 in a bare ubuntu:24.04 container. GitHub's runners set a UTF-8 LANG, so CI never hit it.

Change: in getLocale(), if no locale was asked for and the resulting locale doesn't lowercase É, fall back to C.UTF-8, C.utf8, then en_US.UTF-8. It checks the behaviour rather than locale.name(), because macOS libc++ reports an empty name both with and without LANG. An explicitly passed locale is used unchanged. The MinGW branch is untouched.

No package is needed: C.utf8 ships in glibc's libc-bin.

Tested

  • Ubuntu 24.04 container, LANG unset: before tolower(É) = É (fail), after = é (pass); with LANG=C.UTF-8, unchanged.
  • macOS, tests/utils/strings built with make and run with env -i (no LANG): 43/43 passed; with LANG=en_US.UTF-8: 43/43 passed.

With no locale argument these use the environment's locale. When LANG is
unset (Docker images, chroots, some services) that is "C", which only maps
ASCII case, so ofToLower("É") returned "É" and the strings test failed on a
bare Ubuntu 24.04 container. If the locale maps no non-ASCII case, fall back
to C.UTF-8 (part of glibc's libc-bin), C.utf8 or en_US.UTF-8.

A locale passed explicitly is still used as is.
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.

1 participant