colder          Wed Feb 13 16:59:56 2008 UTC

  Modified files:              
    /php-src/ext/standard       string.c 
    /php-src/ext/standard/tests/strings substr.phpt substr_compare.phpt 
  Log:
  Fix inconcistencies between substr and substr_compare
  
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/string.c?r1=1.667&r2=1.668&diff_format=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.667 php-src/ext/standard/string.c:1.668
--- php-src/ext/standard/string.c:1.667 Tue Feb 12 01:03:43 2008
+++ php-src/ext/standard/string.c       Wed Feb 13 16:59:56 2008
@@ -18,7 +18,7 @@
    +----------------------------------------------------------------------+
  */
 
-/* $Id: string.c,v 1.667 2008/02/12 01:03:43 stas Exp $ */
+/* $Id: string.c,v 1.668 2008/02/13 16:59:56 colder Exp $ */
 
 /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
 
@@ -7985,10 +7985,6 @@
                                --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 @@
                        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)));
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/strings/substr.phpt?r1=1.3&r2=1.4&diff_format=u
Index: php-src/ext/standard/tests/strings/substr.phpt
diff -u php-src/ext/standard/tests/strings/substr.phpt:1.3 
php-src/ext/standard/tests/strings/substr.phpt:1.4
--- php-src/ext/standard/tests/strings/substr.phpt:1.3  Mon Jul  9 11:38:34 2007
+++ php-src/ext/standard/tests/strings/substr.phpt      Wed Feb 13 16:59:56 2008
@@ -75,6 +75,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";
 
@@ -218,6 +222,9 @@
 *** Testing for string with international characters ***
 string(26) "ñtërnâtiônàlizætiøn"
 
+*** Start before the first char ***
+string(4) "abcd"
+
 Done
 --UEXPECTF--
 *** Testing for error conditions ***
@@ -358,4 +365,7 @@
 *** Testing for string with international characters ***
 unicode(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.6&r2=1.7&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.6 
php-src/ext/standard/tests/strings/substr_compare.phpt:1.7
--- php-src/ext/standard/tests/strings/substr_compare.phpt:1.6  Fri Apr 20 
21:37:31 2007
+++ php-src/ext/standard/tests/strings/substr_compare.phpt      Wed Feb 13 
16:59:56 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 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(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)

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

Reply via email to