ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-dev
php-dev
#44830 [Opn->Csd]: Very minor issue with backslash in heredoc
by mattwil other posts by this author
May 9 2008 3:32AM messages near this date
#44830 [NEW]: Very minor issue with backslash in heredoc | #44830 [Opn]: Very minor issue with backslash in heredoc
ID:               44830
 Updated by:       mattwil@[...].net
 Reported By:      slattery at uk dot ibm dot com
-Status:           Open
+Status:           Closed
 Bug Type:         Scripting Engine problem
 Operating System: windows
 PHP Version:      5.2.5
 New Comment:

This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.




Previous Comments:
------------------------------------------------------------------------

[2008-04-28 13:04:49] mattwil@[...].net

Yeah, good catch. (And a backslash would actually always be lost at the
end of a heredoc, even with other text before it.) Because of a check in
the loop that scans for escape sequences, the \ becomes \0 (null byte).

For the devs: I removed the additional check for end of string. All
that will happen with this reproduce code is variable "s" will be
incremented past the end of the string at the end of the while () -- but
I believe that's safe because it won't be read from afterwards.

Patches for all 3 branches:
http://realplain.com/php/bug44830.diff
http://realplain.com/php/bug44830_5_3.diff
http://realplain.com/php/bug44830_5_2.diff

------------------------------------------------------------------------

[2008-04-25 11:21:28] slattery at uk dot ibm dot com

Description:
------------
There is a very minor issue when a heredoc contains only a single
backslash.

The doc says heredoc behaves exactly as double quoted string - so in
this one particular case of the single backslash - we have a case which
cannot be produced in a double quoted string - so the behaviour is
undefined.

The engine appears to treat is as a 'record separator', but I think
it would be better treated as a backslash.

Im quite happy for this to be closed as bogus - Its just that the code
below is from a php test case - I dont suppose anyone will actually do
this.

Reproduce code:
---------------
<?php
$heredoc_string_only_backslash =<<<EOT
EOT;

$str = $heredoc_string_only_backslash;
var_dump(bin2hex($str));

$str_addslashes = addslashes($str);
var_dump(bin2hex($str_addslashes));

$str_stripslashes = stripslashes($str_addslashes);
var_dump(bin2hex($str_stripslashes));
?> 



Expected result:
----------------
On running the code  I get: 

string(2) "00"
string(4) "5c30"
string(2) "00"

which looks a little strange, I would have expected: 

string(2) "5c"
string(4) "5c5c"
string(2) "5c"




------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=44830&edit=1
Thread:
Slattery At Uk Dot Ibm Dot Com
mattwil
mattwil

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved