From 0fb640c71763ddb1b8017c87cec10fc76764feff Mon Sep 17 00:00:00 2001 From: Sara Golemon Date: Thu, 23 Mar 2017 12:27:33 -0700 Subject: Fix bug where `yield from` is captured too greedily In the following piece of code: ```php function from1234($x) { return $x; } function foo($x) { yield from1234($x); } ``` The statement inside foo is taken as `yield from` `1234($x)` which is neither the intent, nor even legal syntax for an fcall. Do a lookahead for breaking non-label characters after the `yield from` and only accept it if they occur. --- NEWS | 1 + Zend/tests/generators/yield_from_greedy_parse.phpt | 24 ++++++++++++++++++++++ Zend/zend_language_scanner.l | 3 ++- 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 Zend/tests/generators/yield_from_greedy_parse.phpt diff --git a/NEWS b/NEWS index f2f392c791..f82f68cb91 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,7 @@ PHP NEWS referenced return). (Nikita) . Fixed bug #74265 (Build problems after 7.0.17 release: undefined reference to `isfinite'). (Nikita) + . Fixed bug #74302 (yield fromLABEL is over-greedy). (Sara) - Date: . Fixed bug #72096 (Swatch time value incorrect for dates before 1970). (mcq8) diff --git a/Zend/tests/generators/yield_from_greedy_parse.phpt b/Zend/tests/generators/yield_from_greedy_parse.phpt new file mode 100644 index 0000000000..598fb515b4 --- /dev/null +++ b/Zend/tests/generators/yield_from_greedy_parse.phpt @@ -0,0 +1,24 @@ +--TEST-- +yield from parses too greedily +--FILE-- +"yield"{WHITESPACE}"from" { +"yield"{WHITESPACE}"from"[^a-zA-Z0-9_\x80-\xff] { + yyless(--yyleng); HANDLE_NEWLINES(yytext, yyleng); RETURN_TOKEN(T_YIELD_FROM); } -- cgit v1.2.1