Re: ereg_replace returns wrong characters
| From: | Rui Hirokawa | Date: | Thu, 02 May 2002 23:38:23 +0000 |
| Subject: | Re: ereg_replace returns wrong characters | ||
| References: | 1 2 | Groups: | php.qa |
| Request: | Send a blank email to php-qa+get-5303@lists.php.net to get a copy of this message | ||
I can show you some examples in real world.
In session.inc of PHPlib 7.4pre1, there is code to remove session id,
case "get":
if ( isset($HTTP_SERVER_VARS["QUERY_STRING"]) && ("" !=
$HTTP_SERVER_VARS["QUERY_STRING"]) ) {
$HTTP_SERVER_VARS["QUERY_STRING"] = ereg_replace(
"(^|&)".quotemeta(urlencode($this->name))."=".$id."(&|$)",
"\\1", $HTTP_SERVER_VARS["QUERY_STRING"]);
}
It assumes this expression matches beginnings of string or '&' and
it can be referable using back-reference operator \\1.
For example, some user used http://foo?SessionID=123456 as
url,
QUERY_STRING is 'SessionID=123456'.
It should be replaced as empty string, and it works fine in PHP 4.1.x or older.
But it is replaced as '\1' in PHP 4.2.0/PHP 4.2.1RC1.
This kind of matching expression is based on POSIX regex and widely used.
Rui
On Thu, 2 May 2002 17:15:33 +0100
"Liz" <liz@xcalibur.demon.co.uk> wrote:
> I was gonna say, I ran this script and it returned exactly what I
> thought it should.. So, Im puzzled to. Can you do a script and comment
> at the end what output you were expecting?
>
> > -----Original Message-----
> > From: derick@php.net [mailto:derick@php.net]
> > Sent: Thursday, May 02, 2002 8:57 AM
> > To: andrei@php.net; Rui Hirokawa
> > Cc: PHP Quality Assurance Team Mailing List
> > Subject: Re: [PHP-QA] ereg_replace returns wrong characters
> >
> >
> > Hello,
> >
> > as far as I know the current behavior is the right one.
> >
> > Andrei, can you enlighten us?
> >
> > Derick
> >
> > On Thu, 2 May 2002, Rui Hirokawa wrote:
> >
> > >
> > > I think the bug #16969 is critical one because
> > > it affects PHPlib's session id propagation in GET mode.
> > > I made a patch to fix this problem.
> > > Could I apply this fix for PHP 4.2.1RC1/PHP 4.3.0dev ?
> > >
> > > -------------------------------------------------
> > > Bug #16959: ereg_replace returns wrong characters
> > >
> > > This is small script for testing.
> > > <?php
> > > $pat = "(^|&)foo(&|$)";
> > > $string = "foo";
> > > echo ereg_replace($pat, "\\1", $string);
> > > ?>
> > >
> > > In PHP <= 4.1.x, this script returns empty string.
> > > But, PHP 4.2.0 and PHP 4.2.1RC1 return '\1'.
> > > The return value in PHP >= 4.2.0 should be corrected.
> > > ereg_replace() is used for session id propagation in GET
> > mode of PHPlib.
> > > It is not work well because
> > > it is affected by this problem.
> > >
> > >
> > > --
> > > -----------------------------------------------------
> > > Rui Hirokawa <rui_hirokawa@ybb.ne.jp>
> > > <hirokawa@php.net>
> > >
> >
> > --------------------------------------------------------------
> > ---------
> > Did I help you? Consider a gift:
> >
> > http://www.amazon.co.uk/exec/obidos/registry/SLCB276UZU8B
> > --------------------------------------------------------------
> > ---------
> > PHP: Scripting the Web - derick@php.net
> > All your branches are belong to me!
> > SRM: Script Running Machine - www.vl-srm.net
> > --------------------------------------------------------------
> > ---------
> >
> >
> > --
> > PHP Quality Assurance Mailing List
> > <http://www.php.net/>
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
--
-----------------------------------------------------
Rui Hirokawa <rui_hirokawa@ybb.ne.jp>
<hirokawa@php.net>