php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76965 INI_SCANNER_RAW doesn't strip trailing whitespace
Submitted: 2018-10-03 02:15 UTC Modified: 2018-10-08 13:39 UTC
From: mb at iname dot com Assigned:
Status: Closed Package: *General Issues
PHP Version: 7.1.22 OS: CentOS
Private report: No CVE-ID: None
 [2018-10-03 02:15 UTC] mb at iname dot com
Description:
------------
When a line contains a comment after the value, parse_ini_string and parse_ini_file in INI_SCANNER_RAW mode pass double quotes and optionally spaces into the value, but strip the semicolon and comment. Logically, if inline comments (comments not taking the whole line) are supported, they should be stripped before parsing the values. If such comments are not supported, they should be included into the value. If this is normal and expected behaviour, it should be documented.

Test script:
---------------
<?php
$ini = <<<END
[section]
1="Hello"
2="Hello" ; comment
END;

var_dump(parse_ini_string($ini,true,INI_SCANNER_RAW));

$tmp = tempnam('.','tmp');
file_put_contents($tmp,$ini);

var_dump(parse_ini_file($tmp,true,INI_SCANNER_RAW));

unlink($tmp);

Expected result:
----------------
Expecting either to elements 1 and 2 with the same value, or element 2 containing the inline comment if inline comments are not supported.

Actual result:
--------------
array(1) {
  ["section"]=>
  array(2) {
    [1]=>
    string(5) "Hello"
    [2]=>
    string(8) ""Hello" "
  }
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-03 09:34 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2018-10-03 09:34 UTC] cmb@php.net
Confirmed: <https://3v4l.org/7FQHA>.

For consistency with INI_SCANNER_NORMAL and INI_SCANNER_TYPED we
should support inline comments also for INI_SCANNER_RAW.
 [2018-10-03 11:15 UTC] cmb@php.net
-Summary: parse_ini_file, parse_ini_string INI_SCANNER_RAW and inline comments +Summary: INI_SCANNER_RAW doesn't strip trailing whitespace
 [2018-10-03 11:15 UTC] cmb@php.net
This is not particularly related to trailing line comments, but
rather to trailing whitespace generally.

<https://github.com/php/php-src/pull/3572> is supposed to fix the
issue.
 [2018-10-08 13:39 UTC] cmb@php.net
The former PR has been superseeded by
<https://github.com/php/php-src/pull/3587>.
 [2018-10-09 05:29 UTC] pierrick@php.net
Automatic comment on behalf of pierrick
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f42d7bddc0479651ecf7f9cdf375bba74b609bea
Log: Fixed bug #76965 INI_SCANNER_RAW doesn't strip trailing whitespace
 [2018-10-09 05:29 UTC] pierrick@php.net
-Status: Verified +Status: Closed
 [2018-10-09 05:29 UTC] pierrick@php.net
Automatic comment on behalf of pierrick
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f42d7bddc0479651ecf7f9cdf375bba74b609bea
Log: Fixed bug #76965 INI_SCANNER_RAW doesn't strip trailing whitespace
 [2018-10-09 05:29 UTC] pierrick@php.net
Automatic comment on behalf of pierrick
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f42d7bddc0479651ecf7f9cdf375bba74b609bea
Log: Fixed bug #76965 INI_SCANNER_RAW doesn't strip trailing whitespace
 [2018-10-09 05:29 UTC] pierrick@php.net
Automatic comment on behalf of pierrick
Revision: http://git.php.net/?p=php-src.git;a=commit;h=f42d7bddc0479651ecf7f9cdf375bba74b609bea
Log: Fixed bug #76965 INI_SCANNER_RAW doesn't strip trailing whitespace
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 09:01:30 2024 UTC