#1565 broken ereg_replace call in quoteimap()

Produces PHP errors

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.)



  • Thijs Kinkhorst

    Thijs Kinkhorst - 2004-03-23
    • assigned_to: nobody --> kink
  • Thijs Kinkhorst

    Thijs Kinkhorst - 2004-03-23

    Logged In: YES

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

  • Thijs Kinkhorst

    Thijs Kinkhorst - 2004-05-01
    • status: open --> closed-fixed

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks