mirror of
https://github.com/php/php-src.git
synced 2024-09-21 09:57:23 +00:00
ext/gettext: updating apis accepting domain behavior.
to be more in line with the proper usage ; normally domain should not be empty strings. Close GH-13691
This commit is contained in:
parent
c2d20f48c5
commit
b3410360cc
4
NEWS
4
NEWS
@ -52,8 +52,8 @@ PHP NEWS
|
||||
. Removed the deprecated inet_ntoa call support. (David Carlier)
|
||||
|
||||
- Gettext:
|
||||
. bind_textdomain_codeset now throws an exception on empty domain.
|
||||
(David Carlier)
|
||||
. bind_textdomain_codeset, textdomain and d(*)gettext functions
|
||||
now throw an exception on empty domain. (David Carlier)
|
||||
|
||||
- Hash:
|
||||
. Changed return type of hash_update() to true. (nielsdos)
|
||||
|
@ -323,7 +323,8 @@ PHP 8.4 UPGRADE NOTES
|
||||
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.
|
||||
. bind_textdomain_codeset, textdomain and d(*)gettext functions now throw an exception
|
||||
if the domain argument is empty.
|
||||
|
||||
- Hash:
|
||||
. Changed the return type of hash_update() to true. It was already the case that only
|
||||
|
@ -54,6 +54,9 @@ ZEND_GET_MODULE(php_gettext)
|
||||
if (UNEXPECTED(domain_len > PHP_GETTEXT_MAX_DOMAIN_LENGTH)) { \
|
||||
zend_argument_value_error(_arg_num, "is too long"); \
|
||||
RETURN_THROWS(); \
|
||||
} else if (domain_len == 0) { \
|
||||
zend_argument_value_error(_arg_num, "cannot be empty"); \
|
||||
RETURN_THROWS(); \
|
||||
}
|
||||
|
||||
#define PHP_GETTEXT_LENGTH_CHECK(_arg_num, check_len) \
|
||||
@ -85,8 +88,11 @@ PHP_FUNCTION(textdomain)
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
if (domain != NULL && ZSTR_LEN(domain) != 0 && !zend_string_equals_literal(domain, "0")) {
|
||||
if (domain != NULL) {
|
||||
PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, ZSTR_LEN(domain))
|
||||
}
|
||||
|
||||
if (domain != NULL && !zend_string_equals_literal(domain, "0")) {
|
||||
domain_name = ZSTR_VAL(domain);
|
||||
}
|
||||
|
||||
@ -179,11 +185,6 @@ PHP_FUNCTION(bindtextdomain)
|
||||
|
||||
PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, domain_len)
|
||||
|
||||
if (!domain_len) {
|
||||
zend_argument_value_error(1, "cannot be empty");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
if (dir == NULL) {
|
||||
RETURN_STRING(bindtextdomain(domain, NULL));
|
||||
}
|
||||
@ -292,11 +293,6 @@ 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) {
|
||||
|
@ -13,8 +13,18 @@ var_dump(dcngettext(1,1,1,1,1));
|
||||
var_dump(dcngettext("test","test","test",1,1));
|
||||
var_dump(dcngettext("test","test","test",0,1));
|
||||
var_dump(dcngettext("test","test","test",-1,-1));
|
||||
var_dump(dcngettext("","","",1,1));
|
||||
var_dump(dcngettext("","","",0,1));
|
||||
|
||||
try {
|
||||
dcngettext("","","",1,1);
|
||||
} catch (\ValueError $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
|
||||
try {
|
||||
dcngettext("","","",0,1);
|
||||
} catch (\ValueError $e) {
|
||||
echo $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
|
||||
echo "Done\n";
|
||||
?>
|
||||
@ -23,6 +33,6 @@ string(1) "1"
|
||||
string(4) "test"
|
||||
string(4) "test"
|
||||
string(4) "test"
|
||||
string(0) ""
|
||||
string(0) ""
|
||||
dcngettext(): Argument #1 ($domain) cannot be empty
|
||||
dcngettext(): Argument #1 ($domain) cannot be empty
|
||||
Done
|
||||
|
@ -18,11 +18,18 @@ bindtextdomain ("messages", "./locale");
|
||||
echo textdomain('test'), "\n";
|
||||
echo textdomain(null), "\n";
|
||||
echo textdomain('foo'), "\n";
|
||||
|
||||
try {
|
||||
textdomain('');
|
||||
} catch (\ValueError $e) {
|
||||
echo $e->getMessage();
|
||||
}
|
||||
?>
|
||||
--EXPECT--
|
||||
test
|
||||
test
|
||||
foo
|
||||
textdomain(): Argument #1 ($domain) cannot be empty
|
||||
--CREDITS--
|
||||
Christian Weiske, cweiske@php.net
|
||||
PHP Testfest Berlin 2009-05-09
|
||||
|
Loading…
Reference in New Issue
Block a user