php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68347 parse_ini_file: warning on string containing "on"
Submitted: 2014-11-05 10:19 UTC Modified: 2014-11-07 12:03 UTC
From: cweiske@php.net Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.6.2 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: cweiske@php.net
New email:
PHP Version: OS:

 

 [2014-11-05 10:19 UTC] cweiske@php.net
Description:
------------
An .ini file with a value containing the word "on" (among other characters) leads to the following warning:

> PHP Warning:  syntax error, unexpected BOOL_TRUE in config-git.ini on line 1

As a result, the ini file cannot be parsed and the parse_ini_file returns false.

Test script:
---------------
config-git.ini:
title = a on

parse.php:
<?php
var_dump(parse_ini_file('config-git.ini'));
?>


Expected result:
----------------
array(1) {
  ["title"]=>
  string(4) "a on"
}


Actual result:
--------------
PHP Warning:  syntax error, unexpected BOOL_TRUE in config-git.ini on line 1
 in /home/cweiske/Dev/phorkie/config-parse.php on line 2

Warning: syntax error, unexpected BOOL_TRUE in config-git.ini on line 1
 in /home/cweiske/Dev/phorkie/config-parse.php on line 2
bool(false)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-11-05 13:06 UTC] edgar dot r dot sandi at gmail dot com
Hi cweiske,

I think that is not a bug because when the parser expects a 'on' keyword to be a bool when you use title = a on the space between a and on cause the problem.

If you want use really the a on, surround with quotes like 'a on'

Then the test will pass:
--TEST--
parse_ini_file: warning on string containing "on"
--FILE--
<?php
$file = dirname(__FILE__) .'/bug68347.ini';
file_put_contents($file, "title = 'a on'");
var_dump(parse_ini_file($file));
unlink($file);
?>
--EXPECT--
array(1) {
  ["title"]=>
  string(4) "a on"
}
 [2014-11-05 14:34 UTC] cweiske@php.net
This is from a git-generated config file. So git does not follow the ini spec correctly?

I think PHP's ini file parser should only try to convert "on" to boolean when it's the only characters in the value.
 [2014-11-05 15:59 UTC] edgar dot r dot sandi at gmail dot com
In this case i think that the PHP ini file parser don't is trying convert to boolean the value a on and, it seems that the root problem is because you have a space between two strings without use quotes.

See the Notes section in PHP documentation: http://php.net/manual/en/function.parse-ini-file.php
 [2014-11-07 12:03 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2014-11-07 12:03 UTC] aharvey@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The value should either be quoted, or INI_SCANNER_RAW should be used to prevent option parsing.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 13:01:29 2024 UTC