[PHP-DEV] Bug #10666 Updated: preg_replace 'e' modifier

2001-08-03 Thread smoonen

ID: 10666
User updated by: [EMAIL PROTECTED]
Reported By: [EMAIL PROTECTED]
Old Status: Open
Status: Closed
Bug Type: PCRE related
Operating System: Linux
PHP Version: 4.0.5
New Comment:

Strangely, while the bug referenced in my update at [2001-05-04 13:55:39] was very 
repeatable across several PHP installations, I can no longer duplicate it.

Am closing the bug, though in my dreams I still wish for $n pseudovariables. ;-)

Previous Comments:


[2001-05-04 14:36:12] [EMAIL PROTECTED]

Also, as a merely informational aside, PHP's use of $1 is in this instance actually 
incompatible with Perl.  Perl, in a s///e expression, treats $n as a variable rather 
than expanding it in-place.

Hence my preference. :-)




[2001-05-04 13:55:39] [EMAIL PROTECTED]

Okay.  Then I have a problem with how backslash escaping is inconsistently applied 
when using \\1 and $1.

Specifically, consider the following:

  function f($x) { print $x; }
  $s = "a' \\ \"b";
  $s = preg_replace('/a(.*)b/e', 'f("$1")', $s, -1);

The single quote is escaped; I'd rather it weren't but that's okay.  But the backslash 
itself isn't escaped!  This prevents me from running stripslashes() on the match, 
since I can't guarantee that every backslash has been properly escaped.

Worse, the following will actually fail:

  function f($x) { print $x; }
  $s = "a' \" \\b";
  $s = preg_replace('/a(.*)b/e', 'f("$1")', $s, -1);

Since the final backslash hasn't been escaped, it actually slurps up the second 
double-quote in 'f("$1")'!

I'd like to see either of the following:

  1. $1 treated as a "real" variable, rather than a string
 substitution.  This is convenient, since it saves me
 having to call stripslashes().

  2. Backslash escapes consistently applied in backrefs.
 Specifically, escape existing backslashes in the match.
 Presently, I can't perform a stripslashes() -- and in
 some cases, as indicated above, it fails altogether!




[2001-05-04 13:02:59] [EMAIL PROTECTED]

$n notation was introduced to be similar to Perl. It is exactly equivalent to \\n.

You can't simply use f($1) in the evaluation string because $1 is replaced with the 
matched contents and after replacement it becomes, in your example, f(abc def), which 
is not valid PHP code. So you have to use f("$1") or f('$1').

The fact that it backslash-escapes single and double quotes in matches before 
substituting $1 is a feature, not a bug, otherwise you'd have a really hard time 
figuring out which quotes go where when using evaluation strings.



[2001-05-04 11:27:54] [EMAIL PROTECTED]

Formerly, preg_replace's "e" modifier inserted extraneous backslashes in 
backreferences of "\\1" or '\\1' form.

Ostensibly, the $1 backreference form was added to fix this.  However, the following 
code fails:

  function f($x) { return 'yo'; }
  $s = "xyzabc def123";
  $s = preg_replace('/(abc def)/e', 'f($1)', $s, -1);

It seems to be trying to evaluate $1 as code, rather than as a variable containing the 
contents "abc def".

This is borne out by the fact that the following succeeds:

  $s = preg_replace('/(abc def)/e', 'f("$1")', $s, -1);

But "$1" and '$1' are no better than "\\1" and '\\1', since it still inserts 
extraneous backslashes before single quotes or double quotes (respectively)!!!

I was sincerely hoping that PHP 4.04 and 4.05 would fix this oversight, since my web 
application depends on it.  I'm keeping my fingers crossed that it's just me doing 
something wrong, though I doubt it...






Edit this bug report at http://bugs.php.net/?id=10666&edit=1


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] PHP 4.0 Bug #10668 Updated: preg_replace backquote failure

2001-05-04 Thread smoonen

ID: 10668
User Update by: [EMAIL PROTECTED]
Status: Analyzed
Bug Type: PCRE related
Description: preg_replace backquote failure

H'm...  I'm confused. :-)  To complicate things further, the e-mails display half as 
many backslashes as the web page. :-)  Since I'm not sure what you mean, I'll 
exhaustively list the behaviors:

The following:

  $str = "abc'''def";
  function f($s) { var_dump($s); return "x"; }
  print preg_replace("/c(.*)d/e", "f('\\1')", $str);

gives the error messages I posted earlier.  (That's two backslashes before the 1.)

The following:

  $str = "abc'''def";
  function f($s) { var_dump($s); return "x"; }
  print preg_replace("/c(.*)d/e", "f('1')", $str);

gives the result:

  string(2) "\1" abxef

which isn't what I want.  (That's four backslashes before the 1.)

Prefixing the "1" with one or three backslashes in each case emits an ASCII x'01'.

None of which are what I want to occur...



Previous Comments:
---

[2001-05-04 15:17:51] [EMAIL PROTECTED]
Oops, \1 instead of 1.

---

[2001-05-04 15:17:15] [EMAIL PROTECTED]
Ok, I made a little mistake, use "f('\\1')" rather than "f('1')".

---

[2001-05-04 13:59:27] [EMAIL PROTECTED]
Oddly, I get the following error:

  Warning: Unexpected character in input: '' (ASCII=92) state=1 in 
/home/groups/t/ta/tavi/htdocs/playground/test.php(4) : regexp code on line 1

  Parse error: parse error in /home/groups/t/ta/tavi/htdocs/playground/test.php(4) : 
regexp code on line 1

  Fatal error: Failed evaluating code: f(''\\''') in 
/home/groups/t/ta/tavi/htdocs/playground/test.php on line 4

PHP compile options may be seen at:

  http://tavi.sourceforge.net/playground/phpinfo.php


---

[2001-05-04 12:58:12] [EMAIL PROTECTED]
Can you explain why you think it fails? The following sample (slightly modified from 
yours to dump the $s parameter to function):

$str = "abc'\\''def";
function f($s) { var_dump($s); return "x"; }
print preg_replace("/c(.*)d/e", "f('\1')", $str);

outputs:

string(5) "'\''"
abxef

As it should.

---

[2001-05-04 11:44:19] [EMAIL PROTECTED]
The following code succeeds on PHP 4.03 and PHP 4.04pl1, but fails on PHP 4.05:

  $str = "abc'\\''def";
  function f($s) { return "x"; }
  print preg_replace("/c(.*)d/e", "f('\1')", $str, -1);

This seems to expose *two* underlying bugs:

  1) There appears to be some problem in the regex state
 machine
  2) There is a definite problem with the replacement of
 the backreference with its corresponding string.


---

The remainder of the comments for this report are too long.  To view the rest of the 
comments, please view the bug report online.

Full Bug description available at: http://bugs.php.net/?id=10668


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] PHP 4.0 Bug #10666 Updated: preg_replace 'e' modifier

2001-05-04 Thread smoonen

ID: 10666
User Update by: [EMAIL PROTECTED]
Status: Open
Bug Type: PCRE related
Description: preg_replace 'e' modifier

Also, as a merely informational aside, PHP's use of $1 is in this instance actually 
incompatible with Perl.  Perl, in a s///e expression, treats $n as a variable rather 
than expanding it in-place.

Hence my preference. :-)


Previous Comments:
---

[2001-05-04 13:55:39] [EMAIL PROTECTED]
Okay.  Then I have a problem with how backslash escaping is inconsistently applied 
when using \1 and $1.

Specifically, consider the following:

  function f($x) { print $x; }
  $s = "a' \ "b";
  $s = preg_replace('/a(.*)b/e', 'f("$1")', $s, -1);

The single quote is escaped; I'd rather it weren't but that's okay.  But the backslash 
itself isn't escaped!  This prevents me from running stripslashes() on the match, 
since I can't guarantee that every backslash has been properly escaped.

Worse, the following will actually fail:

  function f($x) { print $x; }
  $s = "a' " \b";
  $s = preg_replace('/a(.*)b/e', 'f("$1")', $s, -1);

Since the final backslash hasn't been escaped, it actually slurps up the second 
double-quote in 'f("$1")'!

I'd like to see either of the following:

  1. $1 treated as a "real" variable, rather than a string
 substitution.  This is convenient, since it saves me
 having to call stripslashes().

  2. Backslash escapes consistently applied in backrefs.
 Specifically, escape existing backslashes in the match.
 Presently, I can't perform a stripslashes() -- and in
 some cases, as indicated above, it fails altogether!


---

[2001-05-04 13:02:59] [EMAIL PROTECTED]
$n notation was introduced to be similar to Perl. It is exactly equivalent to \n.

You can't simply use f($1) in the evaluation string because $1 is replaced with the 
matched contents and after replacement it becomes, in your example, f(abc def), which 
is not valid PHP code. So you have to use f("$1") or f('$1').

The fact that it backslash-escapes single and double quotes in matches before 
substituting $1 is a feature, not a bug, otherwise you'd have a really hard time 
figuring out which quotes go where when using evaluation strings.

---

[2001-05-04 11:27:54] [EMAIL PROTECTED]
Formerly, preg_replace's "e" modifier inserted extraneous backslashes in 
backreferences of "\1" or '\1' form.

Ostensibly, the $1 backreference form was added to fix this.  However, the following 
code fails:

  function f($x) { return 'yo'; }
  $s = "xyzabc def123";
  $s = preg_replace('/(abc def)/e', 'f($1)', $s, -1);

It seems to be trying to evaluate $1 as code, rather than as a variable containing the 
contents "abc def".

This is borne out by the fact that the following succeeds:

  $s = preg_replace('/(abc def)/e', 'f("$1")', $s, -1);

But "$1" and '$1' are no better than "\1" and '\1', since it still inserts extraneous 
backslashes before single quotes or double quotes (respectively)!!!

I was sincerely hoping that PHP 4.04 and 4.05 would fix this oversight, since my web 
application depends on it.  I'm keeping my fingers crossed that it's just me doing 
something wrong, though I doubt it...


---


Full Bug description available at: http://bugs.php.net/?id=10666


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] PHP 4.0 Bug #10668 Updated: preg_replace backquote failure

2001-05-04 Thread smoonen

ID: 10668
User Update by: [EMAIL PROTECTED]
Status: Analyzed
Bug Type: PCRE related
Description: preg_replace backquote failure

Oddly, I get the following error:

  Warning: Unexpected character in input: '\' (ASCII=92) state=1 in 
/home/groups/t/ta/tavi/htdocs/playground/test.php(4) : regexp code on line 1

  Parse error: parse error in /home/groups/t/ta/tavi/htdocs/playground/test.php(4) : 
regexp code on line 1

  Fatal error: Failed evaluating code: f('\''\'') in 
/home/groups/t/ta/tavi/htdocs/playground/test.php on line 4

PHP compile options may be seen at:

  http://tavi.sourceforge.net/playground/phpinfo.php


Previous Comments:
---

[2001-05-04 12:58:12] [EMAIL PROTECTED]
Can you explain why you think it fails? The following sample (slightly modified from 
yours to dump the $s parameter to function):

$str = "abc'\\''def";
function f($s) { var_dump($s); return "x"; }
print preg_replace("/c(.*)d/e", "f('\1')", $str);

outputs:

string(5) "'\''"
abxef

As it should.

---

[2001-05-04 11:44:19] [EMAIL PROTECTED]
The following code succeeds on PHP 4.03 and PHP 4.04pl1, but fails on PHP 4.05:

  $str = "abc'\\''def";
  function f($s) { return "x"; }
  print preg_replace("/c(.*)d/e", "f('\1')", $str, -1);

This seems to expose *two* underlying bugs:

  1) There appears to be some problem in the regex state
 machine
  2) There is a definite problem with the replacement of
 the backreference with its corresponding string.


---


Full Bug description available at: http://bugs.php.net/?id=10668


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] PHP 4.0 Bug #10666 Updated: preg_replace 'e' modifier

2001-05-04 Thread smoonen

ID: 10666
User Update by: [EMAIL PROTECTED]
Old-Status: Closed
Status: Open
Bug Type: PCRE related
Description: preg_replace 'e' modifier

Okay.  Then I have a problem with how backslash escaping is inconsistently applied 
when using \\1 and $1.

Specifically, consider the following:

  function f($x) { print $x; }
  $s = "a' \\ \"b";
  $s = preg_replace('/a(.*)b/e', 'f("$1")', $s, -1);

The single quote is escaped; I'd rather it weren't but that's okay.  But the backslash 
itself isn't escaped!  This prevents me from running stripslashes() on the match, 
since I can't guarantee that every backslash has been properly escaped.

Worse, the following will actually fail:

  function f($x) { print $x; }
  $s = "a' \" \\b";
  $s = preg_replace('/a(.*)b/e', 'f("$1")', $s, -1);

Since the final backslash hasn't been escaped, it actually slurps up the second 
double-quote in 'f("$1")'!

I'd like to see either of the following:

  1. $1 treated as a "real" variable, rather than a string
 substitution.  This is convenient, since it saves me
 having to call stripslashes().

  2. Backslash escapes consistently applied in backrefs.
 Specifically, escape existing backslashes in the match.
 Presently, I can't perform a stripslashes() -- and in
 some cases, as indicated above, it fails altogether!


Previous Comments:
---

[2001-05-04 13:02:59] [EMAIL PROTECTED]
$n notation was introduced to be similar to Perl. It is exactly equivalent to \n.

You can't simply use f($1) in the evaluation string because $1 is replaced with the 
matched contents and after replacement it becomes, in your example, f(abc def), which 
is not valid PHP code. So you have to use f("$1") or f('$1').

The fact that it backslash-escapes single and double quotes in matches before 
substituting $1 is a feature, not a bug, otherwise you'd have a really hard time 
figuring out which quotes go where when using evaluation strings.

---

[2001-05-04 11:27:54] [EMAIL PROTECTED]
Formerly, preg_replace's "e" modifier inserted extraneous backslashes in 
backreferences of "\1" or '\1' form.

Ostensibly, the $1 backreference form was added to fix this.  However, the following 
code fails:

  function f($x) { return 'yo'; }
  $s = "xyzabc def123";
  $s = preg_replace('/(abc def)/e', 'f($1)', $s, -1);

It seems to be trying to evaluate $1 as code, rather than as a variable containing the 
contents "abc def".

This is borne out by the fact that the following succeeds:

  $s = preg_replace('/(abc def)/e', 'f("$1")', $s, -1);

But "$1" and '$1' are no better than "\1" and '\1', since it still inserts extraneous 
backslashes before single quotes or double quotes (respectively)!!!

I was sincerely hoping that PHP 4.04 and 4.05 would fix this oversight, since my web 
application depends on it.  I'm keeping my fingers crossed that it's just me doing 
something wrong, though I doubt it...


---


Full Bug description available at: http://bugs.php.net/?id=10666


-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] Bug #10668: preg_replace backquote failure

2001-05-04 Thread smoonen

From: [EMAIL PROTECTED]
Operating system: Linux
PHP version:  4.0.5
PHP Bug Type: PCRE related
Bug description:  preg_replace backquote failure

The following code succeeds on PHP 4.03 and PHP 4.04pl1, but fails on PHP 4.05:

  $str = "abc'''def";
  function f($s) { return "x"; }
  print preg_replace("/c(.*)d/e", "f('\\1')", $str, -1);

This seems to expose *two* underlying bugs:

  1) There appears to be some problem in the regex state
 machine
  2) There is a definite problem with the replacement of
 the backreference with its corresponding string.



-- 
Edit Bug report at: http://bugs.php.net/?id=10668&edit=1



-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] Bug #10666: preg_replace 'e' modifier

2001-05-04 Thread smoonen

From: [EMAIL PROTECTED]
Operating system: Linux
PHP version:  4.0.5
PHP Bug Type: PCRE related
Bug description:  preg_replace 'e' modifier

Formerly, preg_replace's "e" modifier inserted extraneous backslashes in 
backreferences of "\\1" or '\\1' form.

Ostensibly, the $1 backreference form was added to fix this.  However, the following 
code fails:

  function f($x) { return 'yo'; }
  $s = "xyzabc def123";
  $s = preg_replace('/(abc def)/e', 'f($1)', $s, -1);

It seems to be trying to evaluate $1 as code, rather than as a variable containing the 
contents "abc def".

This is borne out by the fact that the following succeeds:

  $s = preg_replace('/(abc def)/e', 'f("$1")', $s, -1);

But "$1" and '$1' are no better than "\\1" and '\\1', since it still inserts 
extraneous backslashes before single quotes or double quotes (respectively)!!!

I was sincerely hoping that PHP 4.04 and 4.05 would fix this oversight, since my web 
application depends on it.  I'm keeping my fingers crossed that it's just me doing 
something wrong, though I doubt it...



-- 
Edit Bug report at: http://bugs.php.net/?id=10666&edit=1



-- 
PHP Development Mailing List 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]