summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlia Alshanetsky <iliaa@php.net>2005-07-23 19:44:13 +0000
committerIlia Alshanetsky <iliaa@php.net>2005-07-23 19:44:13 +0000
commit29bf2d3a096a3a3df60fc0e04d657706f61ba764 (patch)
tree45d2bd114fcacb900419ce7ee0fd3f7499fc407e
parent985978057065f4011fe8c5a507b6374e92352561 (diff)
downloadphp-git-29bf2d3a096a3a3df60fc0e04d657706f61ba764.tar.gz
Fixed bug in str_word_count() when charlist if specified and "word" starts
with a character found inside the charlist.
-rw-r--r--ext/standard/string.c8
-rw-r--r--ext/standard/tests/strings/str_word_count.phpt12
2 files changed, 11 insertions, 9 deletions
diff --git a/ext/standard/string.c b/ext/standard/string.c
index e5164d5bfb..d48de12172 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -4739,8 +4739,8 @@ PHP_FUNCTION(str_word_count)
}
while (p < e) {
- if (isalpha(*p++)) {
- s = p - 1;
+ 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++;
}
@@ -4761,7 +4761,9 @@ PHP_FUNCTION(str_word_count)
word_count++;
break;
}
- }
+ } else {
+ p++;
+ }
}
if (!type) {
diff --git a/ext/standard/tests/strings/str_word_count.phpt b/ext/standard/tests/strings/str_word_count.phpt
index 49e2c4ba42..0c6c5ae566 100644
--- a/ext/standard/tests/strings/str_word_count.phpt
+++ b/ext/standard/tests/strings/str_word_count.phpt
@@ -118,7 +118,7 @@ array(6) {
[2]=>
string(1) "r"
[3]=>
- string(1) "s"
+ string(2) "1s"
[4]=>
string(3) "bar"
[5]=>
@@ -130,7 +130,7 @@ array(5) {
[1]=>
string(3) "B4r"
[2]=>
- string(1) "s"
+ string(2) "1s"
[3]=>
string(3) "bar"
[4]=>
@@ -181,8 +181,8 @@ array(6) {
string(1) "B"
[6]=>
string(1) "r"
- [9]=>
- string(1) "s"
+ [8]=>
+ string(2) "1s"
[11]=>
string(3) "bar"
[15]=>
@@ -193,8 +193,8 @@ array(5) {
string(3) "F0o"
[4]=>
string(3) "B4r"
- [9]=>
- string(1) "s"
+ [8]=>
+ string(2) "1s"
[11]=>
string(3) "bar"
[15]=>