iliaa Tue Nov 29 11:14:20 2005 EDT Modified files: (Branch: PHP_5_1) /php-src/ext/standard string.c /php-src/ext/standard/tests/strings str_word_count.phpt /php-src NEWS Log: Fixed bug #35427 (str_word_count() handles '-' incorrectly). http://cvs.php.net/diff.php/php-src/ext/standard/string.c?r1=1.445.2.1&r2=1.445.2.2&ty=u Index: php-src/ext/standard/string.c diff -u php-src/ext/standard/string.c:1.445.2.1 php-src/ext/standard/string.c:1.445.2.2 --- php-src/ext/standard/string.c:1.445.2.1 Wed Sep 28 18:39:52 2005 +++ php-src/ext/standard/string.c Tue Nov 29 11:14:17 2005 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: string.c,v 1.445.2.1 2005/09/28 22:39:52 iliaa Exp $ */ +/* $Id: string.c,v 1.445.2.2 2005/11/29 16:14:17 iliaa Exp $ */ /* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */ @@ -4735,33 +4735,38 @@ if (type == 1 || type == 2) { array_init(return_value); } - + + /* first character cannot be ' or -, unless explicitly allowed by the user */ + if ((*p == '\'' && (!char_list || !ch['\''])) || (*p == '-' && (!char_list || !ch['-']))) { + p++; + } + /* last character cannot be -, unless explicitly allowed by the user */ + if (*(e - 1) == '-' && (!char_list || !ch['-'])) { + e--; + } + while (p < e) { - if (isalpha(*p) || (char_list && ch[(unsigned char)*p])) { - s = ++p - 1; - while (isalpha(*p) || *p == '\'' || (*p == '-' && isalpha(*(p+1))) || (char_list && ch[(unsigned char)*p])) { - p++; - } - + s = p; + while (p < e && (isalpha(*p) || (char_list && ch[(unsigned char)*p]) || *p == '\'' || *p == '-')) { + p++; + } + if (p > s) { switch (type) { case 1: buf = estrndup(s, (p-s)); - add_next_index_stringl(return_value, buf, (p-s), 1); - efree(buf); + add_next_index_stringl(return_value, buf, (p-s), 0); break; case 2: buf = estrndup(s, (p-s)); - add_index_stringl(return_value, (s - str), buf, p-s, 1); - efree(buf); + add_index_stringl(return_value, (s - str), buf, p-s, 0); break; default: word_count++; break; } - } else { - p++; } + p++; } if (!type) { http://cvs.php.net/diff.php/php-src/ext/standard/tests/strings/str_word_count.phpt?r1=1.4&r2=1.4.2.1&ty=u Index: php-src/ext/standard/tests/strings/str_word_count.phpt diff -u php-src/ext/standard/tests/strings/str_word_count.phpt:1.4 php-src/ext/standard/tests/strings/str_word_count.phpt:1.4.2.1 --- php-src/ext/standard/tests/strings/str_word_count.phpt:1.4 Sat Jul 23 15:44:12 2005 +++ php-src/ext/standard/tests/strings/str_word_count.phpt Tue Nov 29 11:14:18 2005 @@ -36,7 +36,11 @@ var_dump(str_word_count($str2, 2, array())); var_dump(str_word_count($str2, 2, new stdClass)); var_dump(str_word_count($str2, 2, "")); - +var_dump(str_word_count("foo'0 bar-0var", 2, "0")); +var_dump(str_word_count("'foo'", 2)); +var_dump(str_word_count("'foo'", 2, "'")); +var_dump(str_word_count("-foo-", 2)); +var_dump(str_word_count("-foo-", 2, "-")); ?> --EXPECTF-- array(6) { @@ -225,4 +229,26 @@ string(3) "bar" [15]=> string(3) "foo" -} \ No newline at end of file +} +array(2) { + [0]=> + string(5) "foo'0" + [6]=> + string(8) "bar-0var" +} +array(1) { + [1]=> + string(4) "foo'" +} +array(1) { + [0]=> + string(5) "'foo'" +} +array(1) { + [1]=> + string(3) "foo" +} +array(1) { + [0]=> + string(5) "-foo-" +} http://cvs.php.net/diff.php/php-src/NEWS?r1=1.2027.2.249&r2=1.2027.2.250&ty=u Index: php-src/NEWS diff -u php-src/NEWS:1.2027.2.249 php-src/NEWS:1.2027.2.250 --- php-src/NEWS:1.2027.2.249 Tue Nov 29 03:16:00 2005 +++ php-src/NEWS Tue Nov 29 11:14:19 2005 @@ -13,6 +13,7 @@ - Fixed bug #35456 (+ 1 [time unit] format did not work). (Ilia) - Fixed bug #35431 (PDO crashes when using LAZY fetch with fetchAll). (Wez) - Fixed bug #35430 (PDO crashes on incorrect FETCH_FUNC use). (Tony) +- Fixed bug #35427 (str_word_count() handles '-' incorrectly). (Ilia) - Fixed bug #35422 (strtotime() does not parse times with UTC as timezone). (Ilia) - Fixed bug #35414 (strtotime() no longer works with ordinal suffix). (Ilia)
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php