php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #51094
Patch bug51094.diff revision 2012-06-07 13:32 UTC by pierrick@php.net
revision 2012-06-06 17:00 UTC by pierrick@php.net

Patch bug51094.diff for Filesystem function related Bug #51094

Patch version 2012-06-07 13:32 UTC

Return to Bug #51094 | Download this patch
This patch renders other patches obsolete

Obsolete patches:

Patch Revisions:

Developer: pierrick@php.net

diff --git a/Zend/zend_ini_scanner.l b/Zend/zend_ini_scanner.l
index 0c452e6..c94ff70 100644
--- a/Zend/zend_ini_scanner.l
+++ b/Zend/zend_ini_scanner.l
@@ -347,7 +347,7 @@ DOLLAR_CURLY "${"
 
 SECTION_RAW_CHARS [^\]\n\r]
 SINGLE_QUOTED_CHARS [^']
-RAW_VALUE_CHARS [^\n\r;\000]
+RAW_VALUE_CHARS [^"\n\r;\000]
 
 LITERAL_DOLLAR ("$"([^{\000]|("\\"{ANY_CHAR})))
 VALUE_CHARS         ([^$= \t\n\r;&|~()!"'\000]|{LITERAL_DOLLAR})
@@ -445,12 +445,41 @@ SECTION_VALUE_CHARS ([^$\n\r;"'\]\\]|("\\"{ANY_CHAR})|{LITERAL_DOLLAR})
 	return '=';
 }
 
-<ST_RAW>{RAW_VALUE_CHARS}+ { /* Raw value, only used when SCNG(scanner_mode) == ZEND_INI_SCANNER_RAW. */
-	/* Eat leading and trailing double quotes */
-	if (yytext[0] == '"' && yytext[yyleng - 1] == '"') {
-		SCNG(yy_text)++;
-		yyleng = yyleng - 2;
+<ST_RAW>["] {
+	while (YYCURSOR < YYLIMIT) {
+		switch (*YYCURSOR++) {
+			case '"':
+				yyleng = YYCURSOR - SCNG(yy_text) - 2;
+				SCNG(yy_text)++;
+				zend_ini_escape_string(ini_lval, yytext, yyleng, '"' TSRMLS_CC);
+				return TC_RAW;
+			case '\\':
+				if (YYCURSOR < YYLIMIT) {
+					YYCURSOR++;
+				}
+				break;
+		}
 	}
+	yyleng = YYCURSOR - SCNG(yy_text);
+	zend_ini_escape_string(ini_lval, yytext, yyleng, '"' TSRMLS_CC);
+	return TC_RAW;
+}
+
+<ST_RAW>{RAW_VALUE_CHARS} { /* Raw value, only used when SCNG(scanner_mode) == ZEND_INI_SCANNER_RAW. */
+	while (YYCURSOR < YYLIMIT) {
+		switch (*YYCURSOR) {
+			case ';':
+			case '\r':
+			case '\n':
+			case '\000':
+				yyleng = YYCURSOR - SCNG(yy_text);
+				RETURN_TOKEN(TC_RAW, yytext, yyleng);
+			default:
+				YYCURSOR++;
+				continue;
+		}
+	}
+	yyleng = YYCURSOR - SCNG(yy_text);
 	RETURN_TOKEN(TC_RAW, yytext, yyleng);
 }
 
diff --git a/ext/standard/tests/file/bug51094.phpt b/ext/standard/tests/file/bug51094.phpt
new file mode 100644
index 0000000..7823558
--- /dev/null
+++ b/ext/standard/tests/file/bug51094.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Fixed bug #51094 (parse_ini_file() with INI_SCANNER_RAW cuts a value that includes a semi-colon).
+--FILE--
+<?php
+
+$ini = parse_ini_string('ini="ini;raw"', null, INI_SCANNER_RAW);
+var_dump($ini['ini']);
+$ini = parse_ini_string('ini="ini;raw', null, INI_SCANNER_RAW);
+var_dump($ini['ini']);
+$ini = parse_ini_string('ini=ini;raw', null, INI_SCANNER_RAW);
+var_dump($ini['ini']);
+$ini = parse_ini_string('ini=ini"raw', null, INI_SCANNER_RAW);
+var_dump($ini['ini']);
+$ini = parse_ini_string("ini=\r\niniraw", null, INI_SCANNER_RAW);
+var_dump($ini['ini']);
+--EXPECTF--
+string(7) "ini;raw"
+string(8) ""ini;raw"
+string(3) "ini"
+string(7) "ini"raw"
+string(0) ""
+
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Nov 23 16:01:27 2024 UTC