php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45384 parse_ini_file will result in parse error with no trailing newline
Submitted: 2008-06-28 03:05 UTC Modified: 2008-08-17 21:18 UTC
From: asonge@php.net Assigned:
Status: Closed Package: Filesystem function related
PHP Version: 5.3CVS-2008-06-28 (CVS) OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: asonge@php.net
New email:
PHP Version: OS:

 

 [2008-06-28 03:05 UTC] asonge@php.net
Description:
------------
an ini file with no trailing newline will result in "Parse error", php5.3 only, 5.2 parses the file fine

Reproduce code:
---------------
$ echo -n "foo.bar = baz" > test.ini
$ /opt/php53/bin/php -r 'var_dump(parse_ini_file("test.ini"));'

Expected result:
----------------
array(1) {
  ["foo.bar"]=>
  string(3) "baz"
}


Actual result:
--------------
Warning: syntax error, unexpected $end in test.ini on line 1
 in Command line code on line 1

Call Stack:
    0.0003     312916   1. {main}() Command line code:0
    0.0128     312936   2. parse_ini_file() Command line code:1

array(0) {
}


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-06-28 11:22 UTC] mattwil@php.net
This is probably also related to the re2c/YYFILL() scanner issues I described in Bug #45372.

I assume it's because a variable length rule is matching ("baz" in your example) when it hits EOF and YYFILL() causes a return/abort. This (unexpected $end) is more likely to happen with ini parsing, etc. where it doesn't usually happen with VALID code in a PHP script because the last thing matched in a typical file is with a fixed length rule (e.g. "?>" or ";"), and these things only happen with variable length matches as I explained in the other bug, though they shouldn't with working scanner code, IMO.


BTW, does putting a space or something other than a newline after baz allow it to work? Any character that's not allowed in the rule matching baz should also make it "magically" work. :-)
 [2008-06-29 00:50 UTC] asonge@php.net
$ echo -n "foo.bar = baz " > test.ini
20:46 alex@asonge:~
$ /opt/php53/bin/php -r 'var_dump(parse_ini_file("test.ini"));'
array(1) {
  ["foo.bar"]=>
  string(4) "baz "
}

so the answer is, yes, a trailing space does not cause the error...if this needs to be marked as a duplicate, whatever it takes to get this working the same as php<=5.2
 [2008-07-29 11:18 UTC] mats dot lindh at gmail dot com
The fix to #45372 did not fix this issue, the problem is still in both the PHP5_3 and HEAD branches.
 [2008-08-17 21:18 UTC] lbarnaud@php.net
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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC