Bug #68347 [Opn]: parse_ini_file: warning on string containing "on"

From: Date: Wed, 05 Nov 2014 14:34:55 +0000
Subject: Bug #68347 [Opn]: parse_ini_file: warning on string containing "on"
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-188464@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68347&edit=1

 ID:                 68347
 Updated by:         cweiske@php.net
 Reported by:        cweiske@php.net
 Summary:            parse_ini_file: warning on string containing "on"
 Status:             Open
 Type:               Bug
 Package:            Unknown/Other Function
 PHP Version:        5.6.2
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[2014-11-05 13:06:07] 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 10:19:03] 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)



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=68347&edit=1


Thread (5 messages)

« previous php.bugs (#188464) next »