1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 08:12:21 +01:00

ext/gettext: bind_textdomain_codeset should not accept empty domains.

the man page specifies that for bind_textdomain_codeset, like
bindtextdomain, the domain should not be an empty string.

close GH-13571
This commit is contained in:
David Carlier
2024-03-02 11:04:22 +00:00
parent 1b380d6ad5
commit 7f01871915
4 changed files with 26 additions and 3 deletions

4
NEWS
View File

@@ -47,6 +47,10 @@ PHP NEWS
- FTP:
. Removed the deprecated inet_ntoa call support. (David Carlier)
- Gettext:
. bind_textdomain_codeset now throws an exception on empty domain.
(David Carlier)
- IMAP:
. Moved to PECL. (Derick Rethans)

View File

@@ -324,6 +324,9 @@ PHP 8.4 UPGRADE NOTES
. DOMDocument::registerNodeClass() now has a tentative return type of true.
Previously, the return type was bool but only true could be returned in practice.
- Gettext:
. bind_textdomain_codeset now throws an exception if the domain's argument is empty.
- Intl:
. IntlDateFormatter::__construct() throws a ValueError if the locale is invalid.
. NumberFormatter::__construct() throws a ValueError if the locale is invalid.

View File

@@ -171,7 +171,7 @@ PHP_FUNCTION(bindtextdomain)
PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, domain_len)
if (domain[0] == '\0') {
if (!domain_len) {
zend_argument_value_error(1, "cannot be empty");
RETURN_THROWS();
}
@@ -283,6 +283,11 @@ PHP_FUNCTION(bind_textdomain_codeset)
PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, domain_len)
if (!domain_len) {
zend_argument_value_error(1, "cannot be empty");
RETURN_THROWS();
}
retval = bind_textdomain_codeset(domain, codeset);
if (!retval) {

View File

@@ -4,13 +4,24 @@ test if bind_textdomain_codeset() returns correct value
gettext
--FILE--
<?php
var_dump(bind_textdomain_codeset(false,false));
try {
bind_textdomain_codeset(false,false);
} catch (ValueError $e) {
echo $e->getMessage() . PHP_EOL;
}
try {
bind_textdomain_codeset("", "UTF-8");
} catch (ValueError $e) {
echo $e->getMessage() . PHP_EOL;
}
var_dump(bind_textdomain_codeset('messages', "UTF-8"));
echo "Done\n";
?>
--EXPECT--
bool(false)
bind_textdomain_codeset(): Argument #1 ($domain) cannot be empty
bind_textdomain_codeset(): Argument #1 ($domain) cannot be empty
string(5) "UTF-8"
Done
--CREDITS--