summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-10-27 16:58:59 (GMT)
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2011-10-27 16:58:59 (GMT)
commit0c08c0645f60e7fa046695087de334c9a384b634 (patch)
treed4e850f96f6814fa1243f98dcb26176499550130
parentb8b3b7747432d5d5535f48db79aa97a11857d58a (diff)
downloadNet_IMAP4-0c08c0645f60e7fa046695087de334c9a384b634.tar.gz
Avoid $str[0] over strlen($str) < 1
-rw-r--r--lib/Net/IMAP4.php121
1 files changed, 63 insertions, 58 deletions
diff --git a/lib/Net/IMAP4.php b/lib/Net/IMAP4.php
index ae63a47..eca88f9 100644
--- a/lib/Net/IMAP4.php
+++ b/lib/Net/IMAP4.php
@@ -3747,73 +3747,78 @@
// remove spaces from the beginning of the string
$str = ltrim($str);
+ if (strlen($str) < 1) {
+ $result[] = '';
+ continue;
+ }
+
switch ($str[0]) {
- // String literal
- case '{':
- if (($epos = strpos($str, "}\r\n", 1)) == false) {
- // error
- }
- if (!is_numeric(($bytes = substr($str, 1, $epos - 1)))) {
- // error
- }
- $result[] = $bytes ? substr($str, $epos + 3, $bytes) : '';
- // Advance the string
- $str = substr($str, $epos + 3 + $bytes);
- break;
+ // String literal
+ case '{':
+ if (($epos = strpos($str, "}\r\n", 1)) == false) {
+ // error
+ }
+ if (!is_numeric(($bytes = substr($str, 1, $epos - 1)))) {
+ // error
+ }
+ $result[] = $bytes ? substr($str, $epos + 3, $bytes) : '';
+ // Advance the string
+ $str = substr($str, $epos + 3 + $bytes);
+ break;
- // Quoted string
- case '"':
- $len = strlen($str);
+ // Quoted string
+ case '"':
+ $len = strlen($str);
- for ($pos=1; $pos<$len; $pos++) {
- if ($str[$pos] == '"') {
- break;
- }
- if ($str[$pos] == "\\") {
- if ($str[$pos + 1] == '"' || $str[$pos + 1] == "\\") {
- $pos++;
+ for ($pos=1; $pos<$len; $pos++) {
+ if ($str[$pos] == '"') {
+ break;
+ }
+ if ($str[$pos] == "\\") {
+ if ($str[$pos + 1] == '"' || $str[$pos + 1] == "\\") {
+ $pos++;
+ }
}
}
- }
- if ($str[$pos] != '"') {
- // error
- }
- // we need to strip slashes for a quoted string
- $result[] = stripslashes(substr($str, 1, $pos - 1));
- $str = substr($str, $pos + 1);
- break;
-
- // Parenthesized list
- case '(':
- case '[':
- $str = substr($str, 1);
- $result[] = self::__tokenize_response($str);
- break;
- case ')':
- case ']':
- $str = substr($str, 1);
- return $result;
- break;
+ if ($str[$pos] != '"') {
+ // error
+ }
+ // we need to strip slashes for a quoted string
+ $result[] = stripslashes(substr($str, 1, $pos - 1));
+ $str = substr($str, $pos + 1);
+ break;
- // String atom, number, NIL, *, %
- default:
- // empty or one character
- if ($str === '') {
- break 2;
- }
- if (strlen($str) < 2) {
- $result[] = $str;
- $str = '';
+ // Parenthesized list
+ case '(':
+ case '[':
+ $str = substr($str, 1);
+ $result[] = self::__tokenize_response($str);
+ break;
+ case ')':
+ case ']':
+ $str = substr($str, 1);
+ return $result;
break;
- }
- // excluded chars: SP, CTL, ), [, ]
- if (preg_match('/^([^\x00-\x20\x29\x5B\x5D\x7F]+)/', $str, $m)) {
- $result[] = $m[1] == 'NIL' ? NULL : $m[1];
- $str = substr($str, strlen($m[1]));
- }
- break;
+ // String atom, number, NIL, *, %
+ default:
+ // empty or one character
+ if ($str === '') {
+ break 2;
+ }
+ if (strlen($str) < 2) {
+ $result[] = $str;
+ $str = '';
+ break;
+ }
+
+ // excluded chars: SP, CTL, ), [, ]
+ if (preg_match('/^([^\x00-\x20\x29\x5B\x5D\x7F]+)/', $str, $m)) {
+ $result[] = $m[1] == 'NIL' ? NULL : $m[1];
+ $str = substr($str, strlen($m[1]));
+ }
+ break;
}
}