php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65568 parse_ini_file() and INI_SCANNER_RAW breaks with newlines
Submitted: 2013-08-28 06:29 UTC Modified: 2013-08-28 20:08 UTC
Votes:2
Avg. Score:4.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: kristo at waher dot net Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.5.3 OS: Windows 7
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: kristo at waher dot net
New email:
PHP Version: OS:

 

 [2013-08-28 06:29 UTC] kristo at waher dot net
Description:
------------
parse_ini_file() works correctly if INI_SCANNER_RAW is not used. However once it 
is used then newlines throw errors in code and make it impossible to store any 
newline-including strings in INI files.

It's said that if you want to use newlines in your INI, you must enclose in 
double-quotes. This is true, but not if you use INI_SCANNER_RAW option.

Since the alternative of not using INI_SCANNER_RAW is not an option (due to how it 
converts some strings and values), this is a bug and should be fixed.

Test script:
---------------
INI:
name="thomas 
moore";

SCRIPT:
parse_ini_file('test.ini',false,INI_SCANNER_RAW);

Expected result:
----------------
no error

Actual result:
--------------
Warning: syntax error, unexpected '"' in test.ini on line 2
 in \test.php on line 1

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-28 20:08 UTC] ab@php.net
-Status: Open +Status: Not a bug
 [2013-08-28 20:08 UTC] ab@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

What's exactly the issue you can't use it without INI_SCANNER_RAW? With it the parser 
has no chance to recognize where the value ends, except each value is per line. Consider 
this:

name=thomas 
moore
age=42

Should it give an error at the line 2 already or should it consider the line 3 as the 
continuation of the 'name' item value? Same logic as CSV. Without INI_SCANNER_RAW it's 
clear 

name="thomas 
moore"
age=42
 [2013-08-29 06:57 UTC] kristo at waher dot net
INI_SCANNER_RAW should still allow newlines to be used in the INI. It says that if 
INI_SCANNER_RAW is set, then 'option values will not be parsed'. But a new line is 
not an option value if it is part of a value. This is similar to bug #51094 where 
the semicolon broke INI parsing, if INI_SCANNER_RAW was used.

A new line is an ACCEPTED PART OF INI VALUE according to documentation. 
INI_SCANNER_RAW should not break this. It should either support a direct new line 
or at least the escaped one. More at http://en.wikipedia.org/wiki/INI_file
 [2014-09-27 17:30 UTC] wxiaoguang at gmail dot com
I agree that this is a bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 19:01:29 2024 UTC