From: Etienne Kneuss Date: Wed, 13 Feb 2008 16:59:56 +0000 (+0000) Subject: Fix inconcistencies between substr and substr_compare X-Git-Tag: RELEASE_2_0_0a1~487 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7c89093243504754a8ac5a5cbf646bb5fd252fb2;p=php Fix inconcistencies between substr and substr_compare --- diff --git a/ext/standard/string.c b/ext/standard/string.c index bcb6083cea..43fe859b5f 100644 --- a/ext/standard/string.c +++ b/ext/standard/string.c @@ -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))); diff --git a/ext/standard/tests/strings/substr.phpt b/ext/standard/tests/strings/substr.phpt index ffad0110f6..d98fb4e4f1 100644 Binary files a/ext/standard/tests/strings/substr.phpt and b/ext/standard/tests/strings/substr.phpt differ diff --git a/ext/standard/tests/strings/substr_compare.phpt b/ext/standard/tests/strings/substr_compare.phpt index fb56f2e0aa..2d6749aaf2 100644 --- a/ext/standard/tests/strings/substr_compare.phpt +++ b/ext/standard/tests/strings/substr_compare.phpt @@ -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)