]> granicus.if.org Git - php/commitdiff
Fix inconcistencies between substr and substr_compare
authorEtienne Kneuss <colder@php.net>
Wed, 13 Feb 2008 16:59:56 +0000 (16:59 +0000)
committerEtienne Kneuss <colder@php.net>
Wed, 13 Feb 2008 16:59:56 +0000 (16:59 +0000)
ext/standard/string.c
ext/standard/tests/strings/substr.phpt
ext/standard/tests/strings/substr_compare.phpt

index bcb6083cead762274ea7de3e60374406a41feaa7..43fe859b5ffe5a23934ebd6d385da472f181b541 100644 (file)
@@ -7985,10 +7985,6 @@ PHP_FUNCTION(substr_compare)
                                --len;
                        }
 
-                       if (len > 0) {
-                               php_error_docref(NULL TSRMLS_CC, E_WARNING, "The specified segment exceeds string length");
-                               RETURN_FALSE;
-                       }
                } else {
                        end_offset = s1_len;
                }
@@ -8006,14 +8002,13 @@ PHP_FUNCTION(substr_compare)
                        offset = (offset < 0) ? 0 : offset;
                }
 
-               if (offset > s1_len) {
+               if (offset >= s1_len) {
                        php_error_docref(NULL TSRMLS_CC, E_WARNING, "The start position cannot exceed initial string length");
                        RETURN_FALSE;
                }
 
                if (len > s1_len - offset) {
-                       php_error_docref(NULL TSRMLS_CC, E_WARNING, "The specified segment exceeds string length");
-                       RETURN_FALSE;
+                       len = s1_len - offset;
                }
 
                cmp_len = (uint) (len ? len : MAX(s2_len, (s1_len - offset)));
index ffad0110f6c2d136fac0e2f8f13d3c29e8ceaf66..d98fb4e4f1b1f0a2cb270cf00ba7918e3ca5ae5c 100644 (file)
Binary files a/ext/standard/tests/strings/substr.phpt and b/ext/standard/tests/strings/substr.phpt differ
index fb56f2e0aa9506de25b443390cbcc48628ee97ad..2d6749aaf21b3c60671ceb418cd6e5a66e56ffac 100644 (file)
@@ -9,6 +9,7 @@ var_dump(substr_compare("abcde", "BC", 1, 2, true));
 var_dump(substr_compare("abcde", "bc", 1, 3));
 var_dump(substr_compare("abcde", "cd", 1, 2));
 var_dump(substr_compare("abcde", "abc", 5, 1));
+var_dump(substr_compare("abcde", "abcdef", -10, 10));
 
 var_dump(substr_compare("abcde", -1, 0, NULL, new stdClass));
 echo "Test\n";
@@ -24,8 +25,9 @@ int(0)
 int(1)
 int(-1)
 
-Warning: substr_compare(): The specified segment exceeds string length in %s on line %d
+Warning: substr_compare(): The start position cannot exceed initial string length in %s on line %d
 bool(false)
+int(0)
 
 Warning: substr_compare() expects parameter 5 to be boolean, object given in %s on line %d
 bool(false)
@@ -44,8 +46,9 @@ int(0)
 int(1)
 int(-1)
 
-Warning: substr_compare(): The specified segment exceeds string length in %s on line %d
+Warning: substr_compare(): The start position cannot exceed initial string length in %s on line %d
 bool(false)
+int(0)
 
 Warning: substr_compare() expects parameter 5 to be boolean, object given in %s on line %d
 bool(false)