summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2021-01-25 15:44:44 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2021-01-25 15:44:44 +0100
commit9343ff1ceb64fd1beb8117e4601463fa9f2f1eff (patch)
treee87f8dbb07db7c137dbd75b4fd643a5777a55862
parent7571edc39889bad6de5f35e08117ec9d8e1f08d3 (diff)
parentd319098b24342e9a4e2344dc7f588b74edcaa846 (diff)
downloadphp-git-9343ff1ceb64fd1beb8117e4601463fa9f2f1eff.tar.gz
Merge branch 'PHP-8.0'
* PHP-8.0: Fix #53251: bindtextdomain with null dir doesn't return old value
-rw-r--r--ext/gettext/gettext.c12
-rw-r--r--ext/gettext/gettext.stub.php4
-rw-r--r--ext/gettext/gettext_arginfo.h6
-rw-r--r--ext/gettext/tests/bug53251.phpt23
4 files changed, 36 insertions, 9 deletions
diff --git a/ext/gettext/gettext.c b/ext/gettext/gettext.c
index 1395f01fcb..54965dbcfc 100644
--- a/ext/gettext/gettext.c
+++ b/ext/gettext/gettext.c
@@ -163,11 +163,11 @@ PHP_FUNCTION(dcgettext)
/* {{{ Bind to the text domain domain_name, looking for translations in dir. Returns the current domain */
PHP_FUNCTION(bindtextdomain)
{
- char *domain, *dir;
+ char *domain, *dir = NULL;
size_t domain_len, dir_len;
char *retval, dir_name[MAXPATHLEN];
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &domain, &domain_len, &dir, &dir_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss!", &domain, &domain_len, &dir, &dir_len) == FAILURE) {
RETURN_THROWS();
}
@@ -178,6 +178,10 @@ PHP_FUNCTION(bindtextdomain)
RETURN_THROWS();
}
+ if (dir == NULL) {
+ RETURN_STRING(bindtextdomain(domain, NULL));
+ }
+
if (dir[0] != '\0' && strcmp(dir, "0")) {
if (!VCWD_REALPATH(dir, dir_name)) {
RETURN_FALSE;
@@ -272,10 +276,10 @@ PHP_FUNCTION(dcngettext)
/* {{{ Specify the character encoding in which the messages from the DOMAIN message catalog will be returned. */
PHP_FUNCTION(bind_textdomain_codeset)
{
- char *domain, *codeset, *retval = NULL;
+ char *domain, *codeset = NULL, *retval = NULL;
size_t domain_len, codeset_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss", &domain, &domain_len, &codeset, &codeset_len) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss!", &domain, &domain_len, &codeset, &codeset_len) == FAILURE) {
RETURN_THROWS();
}
diff --git a/ext/gettext/gettext.stub.php b/ext/gettext/gettext.stub.php
index 6c06d1881d..84654ab741 100644
--- a/ext/gettext/gettext.stub.php
+++ b/ext/gettext/gettext.stub.php
@@ -13,7 +13,7 @@ function dgettext(string $domain, string $message): string {}
function dcgettext(string $domain, string $message, int $category): string {}
-function bindtextdomain(string $domain, string $directory): string|false {}
+function bindtextdomain(string $domain, ?string $directory): string|false {}
#ifdef HAVE_NGETTEXT
function ngettext(string $singular, string $plural, int $count): string {}
@@ -28,5 +28,5 @@ function dcngettext(string $domain, string $singular, string $plural, int $count
#endif
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
-function bind_textdomain_codeset(string $domain, string $codeset): string|false {}
+function bind_textdomain_codeset(string $domain, ?string $codeset): string|false {}
#endif
diff --git a/ext/gettext/gettext_arginfo.h b/ext/gettext/gettext_arginfo.h
index a00e361bc9..32811d5b66 100644
--- a/ext/gettext/gettext_arginfo.h
+++ b/ext/gettext/gettext_arginfo.h
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
- * Stub hash: 7d0fe93cb15576756edc5aad71deadae67046690 */
+ * Stub hash: 3fbd90b87dfcbc5a1a0a2aea8d0cc45516e221ce */
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_textdomain, 0, 1, IS_STRING, 0)
ZEND_ARG_TYPE_INFO(0, domain, IS_STRING, 1)
@@ -24,7 +24,7 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bindtextdomain, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, domain, IS_STRING, 0)
- ZEND_ARG_TYPE_INFO(0, directory, IS_STRING, 0)
+ ZEND_ARG_TYPE_INFO(0, directory, IS_STRING, 1)
ZEND_END_ARG_INFO()
#if defined(HAVE_NGETTEXT)
@@ -57,7 +57,7 @@ ZEND_END_ARG_INFO()
#if defined(HAVE_BIND_TEXTDOMAIN_CODESET)
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_bind_textdomain_codeset, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, domain, IS_STRING, 0)
- ZEND_ARG_TYPE_INFO(0, codeset, IS_STRING, 0)
+ ZEND_ARG_TYPE_INFO(0, codeset, IS_STRING, 1)
ZEND_END_ARG_INFO()
#endif
diff --git a/ext/gettext/tests/bug53251.phpt b/ext/gettext/tests/bug53251.phpt
new file mode 100644
index 0000000000..b3e2e9e66c
--- /dev/null
+++ b/ext/gettext/tests/bug53251.phpt
@@ -0,0 +1,23 @@
+--TEST--
+Bug #53251 (bindtextdomain with null dir doesn't return old value)
+--SKIPIF--
+<?php
+if (!extension_loaded('gettext')) die('skip gettext extension not available');
+?>
+--FILE--
+<?php
+var_dump(is_string(bindtextdomain('foo', null)));
+$dir = bindtextdomain('foo', '.');
+var_dump(bindtextdomain('foo', null) === $dir);
+
+var_dump(bind_textdomain_codeset('foo', null));
+var_dump(bind_textdomain_codeset('foo', 'UTF-8'));
+var_dump(bind_textdomain_codeset('foo', null));
+
+?>
+--EXPECT--
+bool(true)
+bool(true)
+bool(false)
+string(5) "UTF-8"
+string(5) "UTF-8"