From ee2ffe42b5a491282d47154c5a8e8c75e919733b Mon Sep 17 00:00:00 2001 From: Alessandro Pasotti Date: Mon, 12 Feb 2024 16:36:16 +0100 Subject: [PATCH] Fix exp parser with multiline comments Fix #55518 --- src/core/qgsexpressionlexer.ll | 4 +++- tests/src/core/testqgsexpression.cpp | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/core/qgsexpressionlexer.ll b/src/core/qgsexpressionlexer.ll index 8c1ae7e6fb24..d00ce9946aff 100644 --- a/src/core/qgsexpressionlexer.ll +++ b/src/core/qgsexpressionlexer.ll @@ -118,7 +118,7 @@ Q_GLOBAL_STATIC_WITH_ARGS(QLocale, cLocale, ("C") ) %} -%s BLOCK_COMMENT +%x BLOCK_COMMENT line_comment \-\-[^\r\n]*[\r\n]? @@ -152,6 +152,7 @@ string "'"{str_char}*"'" { "/*" BEGIN(BLOCK_COMMENT); } + { "*/" BEGIN(INITIAL); [^*\n]+ // eat comment in chunks @@ -159,6 +160,7 @@ string "'"{str_char}*"'" \n yylineno++; } + "NOT" { U_OP(uoNot); return NOT; } "AND" { B_OP(boAnd); return AND; } "OR" { B_OP(boOr); return OR; } diff --git a/tests/src/core/testqgsexpression.cpp b/tests/src/core/testqgsexpression.cpp index a03ad229a9e7..44c830244313 100644 --- a/tests/src/core/testqgsexpression.cpp +++ b/tests/src/core/testqgsexpression.cpp @@ -385,6 +385,9 @@ class TestQgsExpression: public QObject QTest::newRow( "conditions -3" ) << "case" << false; QTest::newRow( "conditions -4" ) << "case when n p end" << false; QTest::newRow( "conditions -5" ) << "case p end" << false; + + QTest::newRow( "multiline comment after bool 1" ) << R"(True/*"b"*/)" << true; + QTest::newRow( "multiline comment after bool 2" ) << "True/*\"\nb\"*/" << true; } void parsing()