Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from php:master #177

Merged
merged 8 commits into from
Dec 19, 2024
Merged

[pull] master from php:master #177

merged 8 commits into from
Dec 19, 2024

Conversation

pull[bot]
Copy link

@pull pull bot commented Dec 19, 2024

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? 💖 Please sponsor : )

orlitzky and others added 8 commits December 19, 2024 18:22
According to POSIX, bindtextdomain() returns "the implementation-
defined default directory pathname used by the gettext family of
functions" when its second parameter is NULL (i.e. when you are
querying the directory corresponding to some text domain and that
directory has not yet been set). Its PHP counterpart is feeding
that result direclty to RETURN_STRING, but this can go wrong in
two ways:

  1. If an error occurs, even POSIX-compliant implementations
     may return NULL.

  2. At least one non-compliant implementation (musl) lacks
     a default directory and returns NULL whenever the domain
     has not yet been bound.

In either of those cases, PHP segfaults on the NULL string. In this
commit we check for the NULL, and RETURN_FALSE when it happens rather
than crashing.

This partially addresses GH #13696
Musl has two quirks that are leading to failed internationalization
tests. First is that the return value of bindtextdomain(..., NULL)
will always be false, rather than an "implementation-defined default
directory," because musl does not have an implementation-defined
default directory. One test needs a special case for this.

Second is that the musl implementation of bind_textdomain_codeset()
always returns NULL. The POSIX-correctness of this is debatable, but
it is roughly equivalent to correct, because musl only support UTF-8,
so the NULL value indicating that the codeset is unchanged from the
locale's codeset (UTF-8) is accurate.

PHP's bind_textdomain_codeset() function however treats NULL as
failure, unconditionally:

  * php/doc-en#4311
  * #17163

This unfortunately causes false to be returned consistently on musl --
even when nothing unexpected has happened -- and naturally this is
affecting several tests. For now we change two tests to accept "false"
in addition to "UTF-8" so that they may pass on musl. If PHP's
bind_textdomain_codeset() is updated to differentiate between NULL and
NULL-with-errno-set, these tests can also be updated once again to
reject the NULL-with-errno result.

This partially addresses GH #13696
The gettext() family of functions under musl does not support codeset
suffixes like ".UTF-8", because the only codeset it understands is
UTF-8. (Yes, it is annoying that it doesn't support the suffix for the
codeset that it does understand; no, I am not in charge.) Thanks to
this, we have six failing tests on musl,

  * FAIL Gettext basic test with en_US locale that should be on nearly
    every system
    [ext/gettext/tests/gettext_basic-enus.phpt]

  * FAIL Test if bindtextdomain() returns string id if no directory path
    is set( if directory path is 'null')
    [ext/gettext/tests/gettext_bindtextdomain-cwd.phpt]

  * FAIL Test dcgettext() functionality
    [ext/gettext/tests/gettext_dcgettext.phpt]

  * FAIL Test dgettext() functionality
    [ext/gettext/tests/gettext_dgettext.phpt]

  * FAIL Test if dngettext() returns the correct translations
    (optionally plural).
    [ext/gettext/tests/gettext_dngettext-plural.phpt]

  * FAIL Test ngettext() functionality
    [ext/gettext/tests/gettext_ngettext.phpt]

These are all fixed by symlinking the en_US.UTF-8 message data to en_US,
where musl is able to find it.

This does not make the situation any better for developers (who don't
know what libc their users will be running), but that problem is
inhereted from C and is not the fault of the gettext extension.

This partially addresses GH #13696
IR commit: 79483000c2a4b918221fa3097ca47b48b3519447
* PHP-8.4:
  Update IR
* PHP-8.3:
  NEWS for GH-17168
  ext/gettext/config.m4: symlink en_US.UTF-8 test bits to en_US for musl
  ext/gettext/tests: fix libintl return values under musl
  ext/gettext/gettext.c: handle NULLs from bindtextdomain()
* PHP-8.4:
  NEWS for GH-17168
  ext/gettext/config.m4: symlink en_US.UTF-8 test bits to en_US for musl
  ext/gettext/tests: fix libintl return values under musl
  ext/gettext/gettext.c: handle NULLs from bindtextdomain()
@pull pull bot added the ⤵️ pull label Dec 19, 2024
@pull pull bot merged commit 4b1c3cf into KornaPhp:master Dec 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants