]> granicus.if.org Git - php/commitdiff
Fix mb_strrpos() with encoding passed as 3rd param
authorNikita Popov <nikita.ppv@gmail.com>
Mon, 29 Oct 2018 17:56:17 +0000 (18:56 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 29 Oct 2018 17:56:17 +0000 (18:56 +0100)
ext/mbstring/mbstring.c
ext/mbstring/tests/mb_strrpos_encoding_3rd_param.phpt [new file with mode: 0644]

index cdecd99385f47e95dff608c1d23614741ff48387..6554bd72bf9c39f80606764329a40395b914f174 100644 (file)
@@ -2399,12 +2399,6 @@ PHP_FUNCTION(mb_strrpos)
                return;
        }
 
-       haystack.no_language = needle.no_language = MBSTRG(language);
-       haystack.encoding = needle.encoding = php_mb_get_encoding(enc_name);
-       if (!haystack.encoding) {
-               RETURN_FALSE;
-       }
-
        if (zoffset) {
                if (Z_TYPE_P(zoffset) == IS_STRING) {
                        enc_name2     = Z_STRVAL_P(zoffset);
@@ -2446,6 +2440,12 @@ PHP_FUNCTION(mb_strrpos)
                }
        }
 
+       haystack.no_language = needle.no_language = MBSTRG(language);
+       haystack.encoding = needle.encoding = php_mb_get_encoding(enc_name);
+       if (!haystack.encoding) {
+               RETURN_FALSE;
+       }
+
        if (offset != 0) {
                size_t haystack_char_len = mbfl_strlen(&haystack);
                if ((offset > 0 && offset > haystack_char_len) ||
diff --git a/ext/mbstring/tests/mb_strrpos_encoding_3rd_param.phpt b/ext/mbstring/tests/mb_strrpos_encoding_3rd_param.phpt
new file mode 100644 (file)
index 0000000..50b48d9
--- /dev/null
@@ -0,0 +1,11 @@
+--TEST--
+Passing encoding as 3rd param to mb_strrpos (legacy)
+--FILE--
+<?php
+
+mb_internal_encoding('UTF-16');
+var_dump(mb_strrpos("abc abc abc", "abc", "UTF-8"));
+
+?>
+--EXPECT--
+int(8)