Skip to content
Merged
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
14 changes: 8 additions & 6 deletions ext/gettext/gettext.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ ZEND_GET_MODULE(php_gettext)
RETURN_THROWS(); \
}

#define PHP_DCGETTEXT_CATEGORY_CHECK(_arg_num, category) \
if (category == LC_ALL) { \
zend_argument_value_error(_arg_num, "cannot be LC_ALL"); \
RETURN_THROWS(); \
}

PHP_MINFO_FUNCTION(php_gettext)
{
php_info_print_table_start();
Expand Down Expand Up @@ -147,9 +153,7 @@ PHP_FUNCTION(dcgettext)

PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, ZSTR_LEN(domain))
PHP_GETTEXT_LENGTH_CHECK(2, ZSTR_LEN(msgid))
if (category == LC_ALL) {
RETURN_STR_COPY(msgid);
}
PHP_DCGETTEXT_CATEGORY_CHECK(3, category)

msgstr = dcgettext(ZSTR_VAL(domain), ZSTR_VAL(msgid), category);

Expand Down Expand Up @@ -264,9 +268,7 @@ PHP_FUNCTION(dcngettext)
PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, domain_len)
PHP_GETTEXT_LENGTH_CHECK(2, msgid1_len)
PHP_GETTEXT_LENGTH_CHECK(3, msgid2_len)
if (category == LC_ALL) {
RETURN_STRING(msgid1);
}
PHP_DCGETTEXT_CATEGORY_CHECK(5, category)

msgstr = dcngettext(domain, msgid1, msgid2, count, category);

Expand Down
19 changes: 14 additions & 5 deletions ext/gettext/tests/dcgettext_lcall.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,18 @@ dcgettext with LC_ALL is undefined behavior.
gettext
--FILE--
<?php
var_dump(dcgettext('dngettextTest', 'item', LC_ALL));
var_dump(dcngettext('dngettextTest', 'item', 'item2', 1, LC_ALL));
try {
dcgettext('dngettextTest', 'item', LC_ALL);
} catch (ValueError $e) {
echo $e->getMessage() . PHP_EOL;
}

try {
dcngettext('dngettextTest', 'item', 'item2', 1, LC_ALL);
} catch (ValueError $e) {
echo $e->getMessage();
}
?>
--EXPECT--
string(4) "item"
string(4) "item"
--EXPECTF--
dcgettext(): Argument #3 ($category) cannot be LC_ALL
dcngettext(): Argument #5 ($category) cannot be LC_ALL