colder          Wed Feb 13 17:02:16 2008 UTC

  Modified files:              (Branch: PHP_5_3)
    /php-src/ext/standard       string.c 
    /php-src/ext/standard/tests/strings substr.phpt substr_compare.phpt 
  Log:
  MFH: Fix inconcistencies between substr and substr_compare
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?r1=1.445.2.14.2.69.2.16&r2=1.445.2.14.2.69.2.17&diff_format=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.445.2.14.2.69.2.16 
php-src/ext/standard/string.c:1.445.2.14.2.69.2.17
--- php-src/ext/standard/string.c:1.445.2.14.2.69.2.16  Tue Feb 12 00:21:15 2008
+++ php-src/ext/standard/string.c       Wed Feb 13 17:02:15 2008
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: string.c,v 1.445.2.14.2.69.2.16 2008/02/12 00:21:15 stas Exp $ */
+/* $Id: string.c,v 1.445.2.14.2.69.2.17 2008/02/13 17:02:15 colder Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -2172,8 +2172,10 @@
        }
        
        f = Z_LVAL_PP(from);
-       if (f > Z_STRLEN_PP(str) || (f < 0 && -f > Z_STRLEN_PP(str))) {
+       if (f > Z_STRLEN_PP(str)) {
                RETURN_FALSE;
+       } else if (f < 0 && -f > Z_STRLEN_PP(str)) {
+               f = 0;
        }
 
        if (l < 0 && (l + Z_STRLEN_PP(str) - f) < 0) {
@@ -5245,14 +5247,13 @@
                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 length cannot 
exceed initial string length");
-               RETURN_FALSE;
+               len = s1_len - offset;
        }
 
        cmp_len = (uint) (len ? len : MAX(s2_len, (s1_len - offset)));
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/substr.phpt?r1=1.1.2.1&r2=1.1.2.1.2.1&diff_format=u
Index: php-src/ext/standard/tests/strings/substr.phpt
diff -u php-src/ext/standard/tests/strings/substr.phpt:1.1.2.1 
php-src/ext/standard/tests/strings/substr.phpt:1.1.2.1.2.1
--- php-src/ext/standard/tests/strings/substr.phpt:1.1.2.1      Sat May 12 
10:15:02 2007
+++ php-src/ext/standard/tests/strings/substr.phpt      Wed Feb 13 17:02:16 2008
@@ -72,6 +72,10 @@
 /* String with international characters */
 echo ("\n*** Testing for string with international characters ***\n");
 var_dump (substr('\xIñtërnâtiônàlizætiøn',3) );
+
+/* start <0 && -start > length */
+echo "\n*** Start before the first char ***\n";
+var_dump (substr("abcd" , -8) );
  
 echo"\nDone";
 
@@ -215,4 +219,7 @@
 *** Testing for string with international characters ***
 string(26) "ñtërnâtiônàlizætiøn"
 
+*** Start before the first char ***
+string(4) "abcd"
+
 Done
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/substr_compare.phpt?r1=1.1.2.2.2.1&r2=1.1.2.2.2.1.2.1&diff_format=u
Index: php-src/ext/standard/tests/strings/substr_compare.phpt
diff -u php-src/ext/standard/tests/strings/substr_compare.phpt:1.1.2.2.2.1 
php-src/ext/standard/tests/strings/substr_compare.phpt:1.1.2.2.2.1.2.1
--- php-src/ext/standard/tests/strings/substr_compare.phpt:1.1.2.2.2.1  Fri Mar 
 9 09:45:14 2007
+++ php-src/ext/standard/tests/strings/substr_compare.phpt      Wed Feb 13 
17:02:16 2008
@@ -9,6 +9,7 @@
 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(1)
 int(-1)
 
-Warning: substr_compare(): The length cannot exceed initial 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)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to