Bug #55091 [NEW]: parse_ini_file: last escaped double-quote of multiline ends read
From:
Operating system: Windows XP, CENTOS
PHP version: 5.3.6
Package: Filesystem function related
Bug Type: Bug
Bug description:parse_ini_file: last escaped double-quote of multiline ends read
Description:
------------
When parsing an ini file with new lines and that the ini file requires
double quotes to be escaped, PHP considers the last double-quote character
in a line as the closing quote regardless if you escape the double-quote.
The story. I was trying to create an ini file to store the my Google
AdSense. I was thinking that it might be a violation in their TOS if I try
to remove the new lines, so I leave it at is.
At first, I tried escaping new lines with \n. But that does not work. It
prints out the actual \n.
From the PHP documentation, there's a comment that it should be \\n. Which
I did and prints out \n. So I did a research. Someone said to use \\\n
which obviously does not work.
So I gave up trying so I use the actual line feed instead of using \n (I've
read that this might be problematic especially if for instance, you code it
in Windows and there's carriage return and then you ported it to Mac which
gives out error when it finds it).
Now, the new line does work. Unfortunately, the moment it sees that the
last character of the line is a double-quote, PHP reads it as an end even
though it escapes with \"
See the result below. The last line ends as "<script
type="text/javascript</div>"
I'm reporting this as a bug because it presents an unexpected outcome to an
execution that should work differently (for the purpose it was created). I
could, in fact, simply retain the original \n coding and do an str_replace
for it.
Also, the example I gave is the way I use it. There are other ways new
lines can be used with parse_ini_file. Its usage, for how it's going to be
used, can become debatable that will eventually come down to "choice"
(developer) and "control" (programmer).
Test script:
---------------
# PHP script
$var = parse_ini_file ('file.ini');
$var .= '</div>';
echo $var;
# ini file
google_ad = "<script type=\"text/javascript\"><!--
google_ad_client = \"xxx\";
google_ad_width = 728;\ngoogle_ad_height = 90;
//-->
</script>
<script type=\"text/javascript\"
src=\"http://pagead2.googlesyndication.com/pagead/show_ads.js\">
</script>"
Actual result:
--------------
<script type="text/javascript"><!--
google_ad_client = "xxx";
google_ad_width = 728;\ngoogle_ad_height = 90;
//-->
</script>
<script type="text/javascript</div>
--
Edit bug report at https://bugs.php.net/bug.php?id=55091&edit=1
--
Try a snapshot (PHP 5.2): https://bugs.php.net/fix.php?id=55091&r=trysnapshot52
Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=55091&r=trysnapshot53
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=55091&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=55091&r=fixed
Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55091&r=needdocs
Fixed in release: https://bugs.php.net/fix.php?id=55091&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=55091&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=55091&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=55091&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=55091&r=support
Expected behavior: https://bugs.php.net/fix.php?id=55091&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=55091&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=55091&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=55091&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=55091&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=55091&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=55091&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=55091&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=55091&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=55091&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=55091&r=mysqlcfg
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=55091&r=trysnapshot54
Thread (1 message)
- PinoyHarryPotter at gmail dot com