Skip to content

Commit 7f01871

Browse files
committed
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
1 parent 1b380d6 commit 7f01871

File tree

4 files changed

+26
-3
lines changed

4 files changed

+26
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ PHP NEWS
4747
- FTP:
4848
. Removed the deprecated inet_ntoa call support. (David Carlier)
4949

50+
- Gettext:
51+
. bind_textdomain_codeset now throws an exception on empty domain.
52+
(David Carlier)
53+
5054
- IMAP:
5155
. Moved to PECL. (Derick Rethans)
5256

UPGRADING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ PHP 8.4 UPGRADE NOTES
324324
. DOMDocument::registerNodeClass() now has a tentative return type of true.
325325
Previously, the return type was bool but only true could be returned in practice.
326326

327+
- Gettext:
328+
. bind_textdomain_codeset now throws an exception if the domain's argument is empty.
329+
327330
- Intl:
328331
. IntlDateFormatter::__construct() throws a ValueError if the locale is invalid.
329332
. NumberFormatter::__construct() throws a ValueError if the locale is invalid.

ext/gettext/gettext.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ PHP_FUNCTION(bindtextdomain)
171171

172172
PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, domain_len)
173173

174-
if (domain[0] == '\0') {
174+
if (!domain_len) {
175175
zend_argument_value_error(1, "cannot be empty");
176176
RETURN_THROWS();
177177
}
@@ -283,6 +283,11 @@ PHP_FUNCTION(bind_textdomain_codeset)
283283

284284
PHP_GETTEXT_DOMAIN_LENGTH_CHECK(1, domain_len)
285285

286+
if (!domain_len) {
287+
zend_argument_value_error(1, "cannot be empty");
288+
RETURN_THROWS();
289+
}
290+
286291
retval = bind_textdomain_codeset(domain, codeset);
287292

288293
if (!retval) {

ext/gettext/tests/gettext_bind_textdomain_codeset-retval.phpt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,24 @@ test if bind_textdomain_codeset() returns correct value
44
gettext
55
--FILE--
66
<?php
7-
var_dump(bind_textdomain_codeset(false,false));
7+
try {
8+
bind_textdomain_codeset(false,false);
9+
} catch (ValueError $e) {
10+
echo $e->getMessage() . PHP_EOL;
11+
}
12+
13+
try {
14+
bind_textdomain_codeset("", "UTF-8");
15+
} catch (ValueError $e) {
16+
echo $e->getMessage() . PHP_EOL;
17+
}
818
var_dump(bind_textdomain_codeset('messages', "UTF-8"));
919

1020
echo "Done\n";
1121
?>
1222
--EXPECT--
13-
bool(false)
23+
bind_textdomain_codeset(): Argument #1 ($domain) cannot be empty
24+
bind_textdomain_codeset(): Argument #1 ($domain) cannot be empty
1425
string(5) "UTF-8"
1526
Done
1627
--CREDITS--

0 commit comments

Comments
 (0)