php / php/php-src

Line breaks in strings inside ini files result in an error when using INI_SCANNER_RAW with parse_ini_file or parse_ini_string

Open
#11,709 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Status: Needs Triage
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

I don't think there should be a difference in the parsing of string literals in INI files between INI_SCANNER_RAW and other scanner modes. "abcd" is parsed the same, it should be as consistant with "ab\ncd".

The following code:

<?php

$ini = <<<EOF
a=42
b="line 1
line 2"
EOF;

var_dump(parse_ini_string($ini, false, INI_SCANNER_NORMAL));
var_dump(parse_ini_string($ini, false, INI_SCANNER_TYPED));
var_dump(parse_ini_string($ini, false, INI_SCANNER_RAW));

Resulted in this output:

array(2) {
  ["a"]=>
  string(2) "42"
  ["b"]=>
  string(13) "line 1
line 2"
}
array(2) {
  ["a"]=>
  int(42)
  ["b"]=>
  string(13) "line 1
line 2"
}

Warning: syntax error, unexpected '"' in Unknown on line 3
 in /in/RTv1g on line 11
bool(false)

But I expected this output instead:

array(2) {
  ["a"]=>
  string(2) "42"
  ["b"]=>
  string(13) "line 1
line 2"
}
array(2) {
  ["a"]=>
  int(42)
  ["b"]=>
  string(13) "line 1
line 2"
}
array(2) {
  ["a"]=>
  string(2) "42"
  ["b"]=>
  string(13) "line 1
line 2"
}

Demo: https://3v4l.org/RTv1g/rfc#vgit.master

PHP Version

all, including master

Operating System

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with the supplied PHP heredoc and compare parse_ini_string using INI_SCANNER_NORMAL, INI_SCANNER_TYPED, and INI_SCANNER_RAW; then trace the INI parser entry points for parse_ini_file and parse_ini_string. Done means multiline quoted strings are accepted in RAW with the same value as in the other scanner modes, with regression coverage for the example.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.