Skip to content

Commit 15ab75b

Browse files
committed
Merge branch 'PHP-5.3' into PHP-5.4
* PHP-5.3: Fixed bug #63512 parse_ini_file() with INI_SCANNER_RAW removes quotes from value
2 parents 2a59f1d + 6dff07a commit 15ab75b

File tree

3 files changed

+59
-19
lines changed

3 files changed

+59
-19
lines changed

Zend/zend_ini_scanner.l

+25-18
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ DOLLAR_CURLY "${"
347347
348348
SECTION_RAW_CHARS [^\]\n\r]
349349
SINGLE_QUOTED_CHARS [^']
350-
RAW_VALUE_CHARS [^"\n\r;\000]
350+
RAW_VALUE_CHARS [^\n\r;\000]
351351
352352
LITERAL_DOLLAR ("$"([^{\000]|("\\"{ANY_CHAR})))
353353
VALUE_CHARS ([^$= \t\n\r;&|~()!"'\000]|{LITERAL_DOLLAR})
@@ -445,33 +445,40 @@ SECTION_VALUE_CHARS ([^$\n\r;"'\]\\]|("\\"{ANY_CHAR})|{LITERAL_DOLLAR})
445445
return '=';
446446
}
447447

448-
<ST_RAW>["] {
448+
<ST_RAW>{RAW_VALUE_CHARS} { /* Raw value, only used when SCNG(scanner_mode) == ZEND_INI_SCANNER_RAW. */
449+
char *sc = NULL;
449450
while (YYCURSOR < YYLIMIT) {
450-
switch (*YYCURSOR++) {
451+
switch (*YYCURSOR) {
451452
case '\n':
452-
SCNG(lineno)++;
453-
break;
454453
case '\r':
455-
if (*YYCURSOR != '\n') {
456-
SCNG(lineno)++;
457-
}
454+
goto end_raw_value_chars;
458455
break;
459-
case '"':
460-
yyleng = YYCURSOR - SCNG(yy_text) - 2;
461-
SCNG(yy_text)++;
462-
RETURN_TOKEN(TC_RAW, yytext, yyleng);
463-
case '\\':
464-
if (YYCURSOR < YYLIMIT) {
465-
YYCURSOR++;
456+
case ';':
457+
if (sc == NULL) {
458+
sc = YYCURSOR;
466459
}
460+
/* no break */
461+
default:
462+
YYCURSOR++;
467463
break;
468464
}
469465
}
466+
end_raw_value_chars:
470467
yyleng = YYCURSOR - SCNG(yy_text);
471-
RETURN_TOKEN(TC_RAW, yytext, yyleng);
472-
}
473468

474-
<ST_RAW>{RAW_VALUE_CHARS}+ { /* Raw value, only used when SCNG(scanner_mode) == ZEND_INI_SCANNER_RAW. */
469+
/* Eat trailing semicolons */
470+
while (yytext[yyleng - 1] == ';') {
471+
yyleng--;
472+
}
473+
474+
/* Eat leading and trailing double quotes */
475+
if (yytext[0] == '"' && yytext[yyleng - 1] == '"') {
476+
SCNG(yy_text)++;
477+
yyleng = yyleng - 2;
478+
} else if (sc) {
479+
YYCURSOR = sc;
480+
yyleng = YYCURSOR - SCNG(yy_text);
481+
}
475482
RETURN_TOKEN(TC_RAW, yytext, yyleng);
476483
}
477484

ext/standard/tests/file/bug51094.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ $ini = parse_ini_string("ini=\r\niniraw", null, INI_SCANNER_RAW);
1515
var_dump($ini['ini']);
1616
--EXPECTF--
1717
string(7) "ini;raw"
18-
string(8) ""ini;raw"
18+
string(4) ""ini"
1919
string(3) "ini"
2020
string(7) "ini"raw"
2121
string(0) ""

ext/standard/tests/file/bug63512.phpt

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Fixed bug #63512 (parse_ini_file() with INI_SCANNER_RAW removes quotes from value).
3+
--FILE--
4+
<?php
5+
6+
$array = parse_ini_string('
7+
int = 123
8+
constant = INSTALL_ROOT
9+
quotedString = "string"
10+
a = INSTALL_ROOT "waa"
11+
b = "INSTALL_ROOT"
12+
c = "waa" INSTALL_ROOT
13+
d = INSTALL_ROOT "INSTALL_ROOT"', false, INI_SCANNER_RAW);
14+
15+
var_dump($array);
16+
--EXPECTF--
17+
array(7) {
18+
["int"]=>
19+
string(3) "123"
20+
["constant"]=>
21+
string(12) "INSTALL_ROOT"
22+
["quotedString"]=>
23+
string(6) "string"
24+
["a"]=>
25+
string(18) "INSTALL_ROOT "waa""
26+
["b"]=>
27+
string(12) "INSTALL_ROOT"
28+
["c"]=>
29+
string(18) ""waa" INSTALL_ROOT"
30+
["d"]=>
31+
string(27) "INSTALL_ROOT "INSTALL_ROOT""
32+
}
33+

0 commit comments

Comments
 (0)