php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63512 parse_ini_file() with INI_SCANNER_RAW removes quotes from value.
Submitted: 2012-11-14 11:53 UTC Modified: 2012-11-16 01:23 UTC
From: arjen at react dot com Assigned: pierrick
Status: Closed Package: Filesystem function related
PHP Version: 5.3.18 OS: All
Private report: No CVE-ID:
 [2012-11-14 11:53 UTC] arjen at react dot com
Description:
------------
An option value containing a constant followed by an quoted string is transformed 
in constant string: CONSTANT "string" => CONSTANT string

This is broken since 5.3.15/5.4.5, probably by fixing 
https://bugs.php.net/bug.php?id=51094

See http://3v4l.org/VkQgF

And INI_SCANNER_RAW isn't really raw, as quotes are removed anyway.
For value = "string" I would expect array('value' => '"string"') as result, so 
one can differentiate between value = "CONSTANT" and value = CONSTANT.

Test script:
---------------
<?php
define('INSTALL_ROOT', "meukee!");

$array = parse_ini_string('
int = 123
constant = INSTALL_ROOT
quotedString = "string"
a = INSTALL_ROOT "waa"
b = "INSTALL_ROOT"
c = "waa" INSTALL_ROOT
d = INSTALL_ROOT "INSTALL_ROOT"', false, INI_SCANNER_RAW);

var_dump($array);

Expected result:
----------------
array(7) {
  ["int"]=>
  string(3) "123"
  ["constant"]=>
  string(12) "INSTALL_ROOT"
  ["quotedString"]=>
  string(6) "string"
  ["a"]=>
  string(16) "INSTALL_ROOT waa"
  ["b"]=>
  string(12) "INSTALL_ROOT"
  ["c"]=>
  string(16) "waa INSTALL_ROOT"
  ["d"]=>
  string(25) "INSTALL_ROOT INSTALL_ROOT"
}

Actual result:
--------------
array(7) {
  ["int"]=>
  string(3) "123"
  ["constant"]=>
  string(12) "INSTALL_ROOT"
  ["quotedString"]=>
  string(6) "string"
  ["a"]=>
  string(18) "INSTALL_ROOT "waa""
  ["b"]=>
  string(12) "INSTALL_ROOT"
  ["c"]=>
  string(18) ""waa" INSTALL_ROOT"
  ["d"]=>
  string(27) "INSTALL_ROOT "INSTALL_ROOT""
}

even better:

array(7) {
  ["int"]=>
  string(3) "123"
  ["constant"]=>
  string(12) "INSTALL_ROOT"
  ["quotedString"]=>
  string(6) ""string""
  ["a"]=>
  string(18) "INSTALL_ROOT "waa""
  ["b"]=>
  string(12) "INSTALL_ROOT"
  ["c"]=>
  string(18) ""waa" INSTALL_ROOT"
  ["d"]=>
  string(27) "INSTALL_ROOT "INSTALL_ROOT""
}

Patches

63512-v3.diff (last revision 2012-11-15 04:46 UTC) by pierrick@php.net)
63512-v2.diff (last revision 2012-11-15 04:12 UTC) by pierrick@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-11-14 12:14 UTC] arjen at react dot com
Warning: expected result and actual result are swapped! :o
 [2012-11-14 15:19 UTC] laruence@php.net
-Assigned To: +Assigned To: pierrick
 [2012-11-14 15:19 UTC] laruence@php.net
pierrick, do you have time to look at this? thanks :)
 [2012-11-15 04:12 UTC] pierrick@php.net
The following patch has been added/updated:

Patch Name: 63512-v2.diff
Revision:   1352952773
URL:        https://bugs.php.net/patch-display.php?bug=63512&patch=63512-v2.diff&revision=1352952773
 [2012-11-15 04:45 UTC] pierrick@php.net
-Assigned To: pierrick +Assigned To: laruence
 [2012-11-15 04:45 UTC] pierrick@php.net
I created a patch for this bug (which also fix #62884).

Could you make a quick code review before I commit it ? 

Thanks
 [2012-11-15 04:46 UTC] pierrick@php.net
The following patch has been added/updated:

Patch Name: 63512-v3.diff
Revision:   1352954789
URL:        https://bugs.php.net/patch-display.php?bug=63512&patch=63512-v3.diff&revision=1352954789
 [2012-11-15 13:32 UTC] arjen at react dot com
With this patch, the old behaviour is restored. But the "eat leading and trailing quotes" does 
not make sense..

var_dump(parse_ini_string('waa = "string" CONSTANT "anotherString"', false, 
INI_SCANNER_RAW));

5.3.18 (wrong):
array(1) {
  ["waa"]=>
  string(29) "string CONSTANT anotherString"
}

with patch (behaviour like in versions < 5.3.15)

array(1) {
  ["waa"]=>
  string(29) "string" CONSTANT "anotherString"
}


Now string appears to be the constant, and CONSTANT a quoted string..

expected/better:
array(1) {
  ["waa"]=>
  string(29) ""string" CONSTANT "anotherString""
}

So IHMO remove this whole trim quotes thingy.
 [2012-11-15 13:39 UTC] laruence@php.net
-Assigned To: laruence +Assigned To: pierreck
 [2012-11-15 13:39 UTC] laruence@php.net
codes looks fine, and new comment coming :)
thanks
 [2012-11-15 23:24 UTC] pierrick@php.net
-Assigned To: pierreck +Assigned To: pierrick
 [2012-11-16 01:23 UTC] pierrick@php.net
Current status is : 
- we can't as suggested keep all " to make a "real" raw, because of BC
- we can't remove all the quotes would not make sense for some cases like
  c = "waa" INSTALL_ROOT
- we need to fix the bug where c="foo;bar" will result in c="foo (This is why the 
commit causing the current bug was first made)

So I think this patch is the best one for the moment since it fix the original 
bug, and keep the old behaviour to keep BC.
 [2012-11-16 23:40 UTC] pierrick@php.net
-Status: Assigned +Status: Closed
 [2012-11-16 23:40 UTC] pierrick@php.net
Automatic comment on behalf of pierrick
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6dff07aa8c6fcf6cd84a2d1726ffcaeef74b9969
Log: Fixed bug #63512 parse_ini_file() with INI_SCANNER_RAW removes quotes from value
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 24 21:01:55 2014 UTC