From 7f28bfc9352f35b4455a2daebbdac299a34dfca6 Mon Sep 17 00:00:00 2001 From: Ilija Tovilo Date: Tue, 16 Jul 2024 17:50:16 +0200 Subject: [PATCH] Fix comments after -> operator Comments should now fall out of ST_LOOKING_FOR_PROPERTY. Fixes GH-14961 Closes GH-14976 --- Zend/tests/gh14961.phpt | 26 ++++++++++++++++++++++++++ Zend/zend_language_scanner.l | 16 ++++++++-------- 2 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 Zend/tests/gh14961.phpt diff --git a/Zend/tests/gh14961.phpt b/Zend/tests/gh14961.phpt new file mode 100644 index 0000000000000..a869cd92dc25e --- /dev/null +++ b/Zend/tests/gh14961.phpt @@ -0,0 +1,26 @@ +--TEST-- +GH-14961: Comments after -> operator +--FILE-- +/* comment */class = 42; +var_dump($c->/** doc comment */class); +var_dump($c-> + // line comment + class); +var_dump($c-> + # hash comment + class); +var_dump($c?->/* comment */class); + +?> +--EXPECT-- +int(42) +int(42) +int(42) +int(42) diff --git a/Zend/zend_language_scanner.l b/Zend/zend_language_scanner.l index c73a50948d6bc..c3b27cbfc321c 100644 --- a/Zend/zend_language_scanner.l +++ b/Zend/zend_language_scanner.l @@ -1587,12 +1587,6 @@ NEWLINE ("\r"|"\n"|"\r\n") RETURN_TOKEN_WITH_STR(T_STRING, 0); } -{ANY_CHAR} { - yyless(0); - yy_pop_state(); - goto restart; -} - "::" { RETURN_TOKEN(T_PAAMAYIM_NEKUDOTAYIM); } @@ -2375,7 +2369,7 @@ inline_char_handler: } -"#"|"//" { +"#"|"//" { while (YYCURSOR < YYLIMIT) { switch (*YYCURSOR++) { case '\r': @@ -2399,7 +2393,7 @@ inline_char_handler: RETURN_OR_SKIP_TOKEN(T_COMMENT); } -"/*"|"/**"{WHITESPACE} { +"/*"|"/**"{WHITESPACE} { int doc_com; if (yyleng > 2) { @@ -2435,6 +2429,12 @@ inline_char_handler: RETURN_OR_SKIP_TOKEN(T_COMMENT); } +{ANY_CHAR} { + yyless(0); + yy_pop_state(); + goto restart; +} + "?>"{NEWLINE}? { BEGIN(INITIAL); if (yytext[yyleng-1] != '>') {