Skip to content

ext/gettext: updating apis accepting domain behavior. #13691

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 7 additions & 11 deletions ext/gettext/gettext.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 14 additions & 4 deletions ext/gettext/tests/dcngettext.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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";
?>
Expand All @@ -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
7 changes: 7 additions & 0 deletions ext/gettext/tests/gettext_textdomain-retval.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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, [email protected]
PHP Testfest Berlin 2009-05-09