#1565 broken ereg_replace call in quoteimap()

Produces PHP errors
closed-fixed
None
5
2004-05-01
2004-03-22
Anonymous
No

File functions/strings.php lines 397-399 read:

function quoteimap($str) {
return ereg_replace('(["\\])', '\\\\1', $str);
}

Because of the way PHP single-quoted strings work
(backslashes are always literal, except when they
precede another backslash or single-quote, in which
case they escape that character), the two strings
actually passed are (["\]) and \\1. This is what gets
passed to the regex functions, which use backslash
normally to escape regex tokens. In the pattern, the
close square bracket is escaped therefore is not
interpreted as end-of-character-class, leaving the class
unterminated which gives a PHP compile error.

The pattern should instead read '(["\\\\])' which will give
the correct regex of (["\\]). preg_replace("/
([\"\\\\])/", "\\\\$1", $str) is another, possibly more
efficient option.

(This error occurs inconsistently - sometimes it works for
a few minutes, then the next few minutes it gives PHP
errors. As far as I can tell it ought to give the error
consistently, but with the above change I've yet to see
the errors at all.)

jssqm@kanargh.force9.co.uk

Discussion

    • assigned_to: nobody --> kink
     
  • Logged In: YES
    user_id=285765

    Thanks for reporting.
    Fixed in devel, if it doesn't give rise to problems, it will
    be backported to stable.

     
    • status: open --> closed-fixed