php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49443 Special characters in section name breaks parse_ini_file
Submitted: 2009-09-02 15:52 UTC Modified: 2009-09-03 08:38 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:1 (50.0%)
From: eric dot caron at gmail dot com Assigned:
Status: Not a bug Package: Filesystem function related
PHP Version: 5.3.0 OS: N/A
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: eric dot caron at gmail dot com
New email:
PHP Version: OS:

 

 [2009-09-02 15:52 UTC] eric dot caron at gmail dot com
Description:
------------
PHP 5.3 changes to parse_ini_*() functions breaks scripts that have special characters, {}|&~![()^", in the section titles. (Previous versions worked, which I assume was proper behavior because section titles can have those characters according to community understood INI standards).

There is no documentation stating that special characters can not be used in section titles. While the INI_SCANNER_RAW parameter provides an opening for a workaround for this solution, to be useful, the characters {}|&~![()^" should be usable in section titles (not to be confuse with keys, where they shouldn't be used).

Reproduce code:
---------------
<?php
$tmpfname = tempnam("/tmp", "FOO");
file_put_contents($tmpfname, '[Ask]
Crawler=true

[Mozilla/?.0 (compatible; Ask Jeeves/Teoma*)]
Crawler=true
');

$array = parse_ini_file($tmpfname, true);
print_r($array);
unlink($tmpfname);

Expected result:
----------------
Array
(
    [Ask] => Array
        (
            [Crawler] => 1
        )

    [Mozilla/?.0 (compatible; Ask Jeeves/Teoma*)] => Array
        (
            [Crawler] => 1
        )

)


Actual result:
--------------
Warning: parse error, expecting `']'' in FOOFCCA.tmp on line 4 in parseBug.php on line 10 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-09-02 19:12 UTC] jani@php.net
The raw option is just for this and it's NOT a workaround but exactly 
the thing you're supposed to use here. No bug here.
 [2009-09-02 19:49 UTC] eric dot caron at gmail dot com
The raw option, though, does not convert the string "true"/"false" to its boolean.

If you change the print_r in my demo code to a var_dump:
*** PHP 5.2 RESULTS ***
array(2) {
  ["Ask"]=>
  array(1) {
    ["Crawler"]=>
    string(1) "1"
  }
  ["Mozilla/?.0 (compatible; Ask Jeeves/Teoma*)"]=>
  array(1) {
    ["Crawler"]=>
    string(1) "1"
  }
}

*** PHP 5.3 RESULTS ***
array(2) {
  ["Ask"]=>
  array(1) {
    ["Crawler"]=>
    string(4) "true"
  }
  ["Mozilla/?.0 (compatible; Ask Jeeves/Teoma*)"]=>
  array(1) {
    ["Crawler"]=>
    string(4) "true"
  }
}
 [2009-09-02 20:02 UTC] eric dot caron at gmail dot com
The logic difficulty is better showcased with "false" values.

*** PHP 5.2 (GOOD) ***
array(2) {
  ["Ask"]=>
  array(1) {
    ["Crawler"]=>
    string(0) ""
  }
  ["Mozilla/?.0 (compatible; Ask Jeeves/Teoma*)"]=>
  array(1) {
    ["Crawler"]=>
    string(1) "1"
  }
}


*** PHP 5.3 (BAD) ***
array(2) {
  ["Ask"]=>
  array(1) {
    ["Crawler"]=>
    string(5) "false"
  }
  ["Mozilla/?.0 (compatible; Ask Jeeves/Teoma*)"]=>
  array(1) {
    ["Crawler"]=>
    string(4) "true"
  }
}
 [2009-09-03 08:38 UTC] jani@php.net
The changes were made exactly to get the browscap.ini parsing to actually work. It did not and does not work in 5.2 properly. This will not change.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 02 01:01:29 2024 UTC