|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-09-03 20:17 UTC] sebastian dot schleussner at angstrom dot uu dot se
Description: ------------ This is a follow-up to Bug #49443. The character breaking parse_ini_file of PHP 5.3.0 with browscap.ini is actually the comment character ";" inside section headers - not one of the special characters. Reproduce code: --------------- ;sample1.ini ; demonstration of what works in 5.2 and 5.3 [a(b){c}&~![^] x=y ;sample2.ini ; demonstration of the problem [a;b];c x=y Code: ----- <?php print_r(parse_ini_file('sample1.ini', true)); print_r(parse_ini_file('sample2.ini', true)); ?> Expected result: ---------------- As in PHP 5.2.10 -- the header's square brackets being interpreted as quoting: Array ( [a(b){c}&~![^] => Array ( [x] => y ) ) Array ( [a;b] => Array ( [x] => y ) ) Actual result: -------------- Array ( [a(b){c}&~![^] => Array ( [x] => y ) ) PHP Warning: syntax error, unexpected $end, expecting ']' in sample2.ini on line 1 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Dec 07 05:00:01 2025 UTC |
Okay, classification as "bug" may be debatable, and note that I have made this a "Feature/Change Request". At the very least, it is an undocumented and irritating change of functionality. Next, it is a change that breaks normal parsing of the widely used browscaps.ini, which PHP's own get_browser still reads flawlessly. Most importantly, semicolons ARE allowed inside quotes, and I think it is very logical to interpret the square brackets of section titles as quoting, too (as pre-5.3 PHP did). There is no legitimate use of a semicolon *for starting a comment* before the closing square bracket, so there is no reason to interpret it as such. If one wants to add a comment on the title line, one can do so after the closing bracket. As to accepted standards: On the one hand my experience is that there is a lot of variation in the format of INI files, so a parser should be reasonably lenient. On the other hand I have never seen backslash escaping in INI files and I'm not at all sure it is part of any "accepted standard" for them. It only works partly anyway, and inconsistently. Take this file: ;sample3.ini [a\;b];c x=y\;z y="a;b" z="a\;b" and run print_r(parse_ini_file("sample3.ini", true)); You get (PHP 5.2.10 and 5.3.0): Array ( [a\;b] => Array ( [x] => y\ [y] => a;b [z] => a\;b ) ) No bailout, but (a) the backslash remains inside title and quotes, (b) the escaping does not work in values. No good, IMHO. Variable z shows that titles and quoted strings are still considered equally in terms of backslashes, and x demos that unquoted ;'s are always filtered, but while the unescaped ; in y is allowed, it's not in the title in 5.3 -- that's inconsistent and should be reverted. I rest my case.