php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42069 parse_ini_file() gives wrong output with some of Non-alpha numeric characters
Submitted: 2007-07-22 15:41 UTC Modified: 2007-09-28 02:09 UTC
From: mahesh dot vemula at in dot ibm dot com Assigned: jani (profile)
Status: Closed Package: PHP options/info functions
PHP Version: 5CVS-2007-07-22 (CVS) OS: RHEL 4, Windows Xp
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: mahesh dot vemula at in dot ibm dot com
New email:
PHP Version: OS:

 

 [2007-07-22 15:41 UTC] mahesh dot vemula at in dot ibm dot com
Description:
------------
PHP engine doesn?t throw the expected parsing error (which is according to doc) with the ?input string given in ?parse.ini file? containing ?@? char and which is not included in double quotes (??). 
Documentation says -
?Note: If a value in the ini file contains any non-alphanumeric characters it needs to be enclosed in double-quotes (") in ?http://in2.php.net/manual/en/function.parse-ini-file.php.
And it is happening with many other Non-alpha numeric chars like #, %, &, +, -, `, ^, <, >, :, ?, _, ?, etc. 
For some of chars like ?!?, ?~?, ?()?, etc php throws parsing error which is expected according to doc.


Environment:
Operating System: Linux, Windows XP
PHP Version:PHP 5.2.4-dev (cli) (built: Jul 21 2007 19:21:35)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
Configure Setup: ./configure


Reproduce code:
---------------
Parse_ini_file.php:
<?php
$ini_array = parse_ini_file(dirname(__FILE__)."/parse.ini");
print_r($ini_array);
?>



parse.ini:
;start of ini file

[Strings with non-alpha numeric values]
;without quotes
;Expected a parse error
Non-alpha_string1 = Hello@world 
;Throws an error, which is according to doc
;Non-alpha_string2 = Hello!world 

;with quotes
;Works fine, which is according to doc
Non-alpha_string1_quotes = "Hello@world"
Non-alpha_string2_quotes = "Hello!world"

;end of ini file


Expected result:
----------------
PHP Warning:  Error parsing %s/parse.ini on line %d in %s\parse_ini_file.php on line %d
Array
(
    [Non-alpha_string2] => Hello
)


Actual result:
--------------
Array
(
    [Non-alpha_string1] => Hello@world
    [Non-alpha_string1_quotes] => Hello@world
    [Non-alpha_string2_quotes] => Hello!world
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-08-07 00:29 UTC] jani@php.net
Actually the manual is wrong, @ is allowed. Only the boolean operators shouldn't be allowed in non-quoted strings. I have rewritten most of the scanner (and parser) to allow pretty much anything in the ini values.

Patch can be seen here: 
http://pecl.php.net/~jani/patches/new_ini_parser_scanner.patch

I will commit this to HEAD and upcoming PHP_5_3 branches along with fixed tests plus some more tests. 

Only the ini keys can not have any non-alphanumeric characters in them, except for _ and . (dot).
 [2007-09-28 02:09 UTC] jani@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.

Fixed in PHP_5_3 branch and HEAD.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed May 28 21:01:26 2025 UTC