From 03c7749dc8f40df8f41afffcdef4595ad43afe7f Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Fri, 23 Aug 2019 13:59:10 +0200 Subject: [PATCH] Fix #77812: Interactive mode does not support PHP 7.3-style heredoc As of PHP 7.3.0, the rules regarding the heredoc and nowdoc closing identifier have been relaxed. While formerly, the closing identifier was required to be placed at the beginning of a line and to be immediately followed by (a semicolon and) a line break, it may now be preceeded by whitespace, and may be followed by any non-word character. We adjust the recognition logic respectively. --- NEWS | 2 + ext/readline/readline_cli.c | 11 +++-- ext/readline/tests/bug77812-libedit.phpt | 34 ++++++++++++++ ext/readline/tests/bug77812-readline.phpt | 54 +++++++++++++++++++++++ 4 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 ext/readline/tests/bug77812-libedit.phpt create mode 100644 ext/readline/tests/bug77812-readline.phpt diff --git a/NEWS b/NEWS index eda4a46ed2..0e6efd76cd 100644 --- a/NEWS +++ b/NEWS @@ -8,6 +8,8 @@ PHP NEWS property). (Nikita) . Fixed bug #78441 (Parse error due to heredoc identifier followed by digit). (cmb) + . Fixed bug #77812 (Interactive mode does not support PHP 7.3-style heredoc). + (cmb, Nikita) - Intl: . Ensure IDNA2003 rules are used with idn_to_ascii() and idn_to_utf8() diff --git a/ext/readline/readline_cli.c b/ext/readline/readline_cli.c index 69ebe117cb..6e6e9161be 100644 --- a/ext/readline/readline_cli.c +++ b/ext/readline/readline_cli.c @@ -347,11 +347,14 @@ static int cli_is_valid_code(char *code, size_t len, zend_string **prompt) /* {{ } break; case heredoc: - if (code[i - (heredoc_len + 1)] == '\n' && !strncmp(code + i - heredoc_len, heredoc_tag, heredoc_len) && code[i] == '\n') { - code_type = body; - } else if (code[i - (heredoc_len + 2)] == '\n' && !strncmp(code + i - heredoc_len - 1, heredoc_tag, heredoc_len) && code[i-1] == ';' && code[i] == '\n') { + if (!strncmp(code + i - heredoc_len + 1, heredoc_tag, heredoc_len)) { + unsigned char c = code[i + 1]; + char *p = code + i - heredoc_len; + + if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9') || c == '_' || c >= 0x80) break; + while (*p == ' ' || *p == '\t') p--; + if (*p != '\n') break; code_type = body; - valid_end = 1; } break; case outside: diff --git a/ext/readline/tests/bug77812-libedit.phpt b/ext/readline/tests/bug77812-libedit.phpt new file mode 100644 index 0000000000..478274a19a --- /dev/null +++ b/ext/readline/tests/bug77812-libedit.phpt @@ -0,0 +1,34 @@ +--TEST-- +Bug #77812 (Interactive mode does not support PHP 7.3-style heredoc) +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +resource(%d) of type (process) +Interactive shell + +bar +xx +xxx + +Warning: Use of undefined constant FOO - assumed 'FOO' (this will throw an Error in a future version of PHP) in php shell code on line %d +FOOL1 +FOO42 diff --git a/ext/readline/tests/bug77812-readline.phpt b/ext/readline/tests/bug77812-readline.phpt new file mode 100644 index 0000000000..32d9f4d960 --- /dev/null +++ b/ext/readline/tests/bug77812-readline.phpt @@ -0,0 +1,54 @@ +--TEST-- +Bug #77812 (Interactive mode does not support PHP 7.3-style heredoc) +--SKIPIF-- + +--FILE-- + +--EXPECTF-- +resource(%d) of type (process) +Interactive shell + +php > echo << bar +<<< > FOO; +bar +php > print(<< xx +<<< > FOO); +xx +php > echo << xxx +<<< > FOO; +xxx +php > FOO +php > ; + +Warning: Use of undefined constant FOO - assumed 'FOO' (this will throw an Error in a future version of PHP) in php shell code on line %d +php > echo << FOOL +<<< > FOO +php > ,1; +FOOL1 +php > echo << FOO4 +<<< > FOO +php > ,2; +FOO42 +php > -- 2.50.0