From: Sara Golemon Date: Sat, 12 Apr 2003 20:04:06 +0000 (+0000) Subject: Add tests for strrpos/stripos, and minor fix to maintain BC for condition with empty... X-Git-Tag: RELEASE_0_5~54 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=76965beb04478defa61d7d32f552247a4c3242e2;p=php Add tests for strrpos/stripos, and minor fix to maintain BC for condition with empty needles/haystacks --- diff --git a/ext/standard/string.c b/ext/standard/string.c index aba93f5059..c329f9e16a 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -1579,6 +1579,10 @@ PHP_FUNCTION(strrpos) RETURN_FALSE; } + if ((haystack_len == 0) || (needle_len == 0)) { + RETURN_FALSE; + } + if (offset >= 0) { p = haystack + offset; e = haystack + haystack_len - needle_len; @@ -1615,6 +1619,10 @@ PHP_FUNCTION(strripos) RETURN_FALSE; } + if ((haystack_len == 0) || (needle_len == 0)) { + RETURN_FALSE; + } + needle_dup = estrndup(needle, needle_len); php_strtolower(needle_dup, needle_len); haystack_dup = estrndup(haystack, haystack_len); diff --git a/ext/standard/tests/strings/strripos.phpt b/ext/standard/tests/strings/strripos.phpt new file mode 100644 index 0000000000..c9c6eae7e3 --- /dev/null +++ b/ext/standard/tests/strings/strripos.phpt @@ -0,0 +1,35 @@ +--TEST-- +strripos() function +--POST-- +--GET-- +--FILE-- + +--EXPECT-- +int(5) +int(12) +int(18) +int(12) +int(10) +int(2) +int(0) +int(0) +bool(false) +bool(false) +bool(false) +bool(false) +int(1) + diff --git a/ext/standard/tests/strings/strrpos.phpt b/ext/standard/tests/strings/strrpos.phpt new file mode 100644 index 0000000000..0d4337605a --- /dev/null +++ b/ext/standard/tests/strings/strrpos.phpt @@ -0,0 +1,34 @@ +--TEST-- +strrpos() function +--POST-- +--GET-- +--FILE-- + +--EXPECT-- +int(5) +int(5) +int(18) +int(12) +int(10) +int(2) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +bool(false) +int(1)