Skip to content

Commit 9cf4508

Browse files
committed
ext/gettext/tests: fix bind_textdomain_codeset() return values under musl
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
1 parent 6f1c108 commit 9cf4508

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

ext/gettext/tests/bug53251.phpt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,22 @@ var_dump(is_string(bindtextdomain('foo', null)));
1212
$dir = bindtextdomain('foo', '.');
1313
var_dump(bindtextdomain('foo', null) === $dir);
1414

15+
// bind_textdomain_codeset() always returns false on musl
16+
// because musl only supports UTF-8. For more information:
17+
//
18+
// * https://github.com/php/doc-en/issues/4311,
19+
// * https://github.com/php/php-src/issues/17163
20+
//
1521
var_dump(bind_textdomain_codeset('foo', null));
16-
var_dump(bind_textdomain_codeset('foo', 'UTF-8'));
17-
var_dump(bind_textdomain_codeset('foo', null));
22+
$result = bind_textdomain_codeset('foo', 'UTF-8');
23+
var_dump(!$result or $result === "UTF-8");
24+
$result = bind_textdomain_codeset('foo', null);
25+
var_dump(!$result or $result === "UTF-8");
1826

1927
?>
2028
--EXPECT--
2129
bool(true)
2230
bool(true)
2331
bool(false)
24-
string(5) "UTF-8"
25-
string(5) "UTF-8"
32+
bool(true)
33+
bool(true)

ext/gettext/tests/gettext_bind_textdomain_codeset-retval.phpt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,22 @@ gettext
1515
} catch (ValueError $e) {
1616
echo $e->getMessage() . PHP_EOL;
1717
}
18-
var_dump(bind_textdomain_codeset('messages', "UTF-8"));
18+
19+
// bind_textdomain_codeset() always returns false on musl
20+
// because musl only supports UTF-8. For more information:
21+
//
22+
// * https://github.com/php/doc-en/issues/4311,
23+
// * https://github.com/php/php-src/issues/17163
24+
//
25+
$result = bind_textdomain_codeset('messages', "UTF-8");
26+
var_dump(!$result or $result === "UTF-8");
1927

2028
echo "Done\n";
2129
?>
2230
--EXPECT--
2331
bind_textdomain_codeset(): Argument #1 ($domain) must not be empty
2432
bind_textdomain_codeset(): Argument #1 ($domain) must not be empty
25-
string(5) "UTF-8"
33+
bool(true)
2634
Done
2735
--CREDITS--
2836
Florian Holzhauer fh-pt@fholzhauer.de

0 commit comments

Comments
 (0)