Skip to content
Permalink
Browse files

Abort expression parsing after encountering a maximum of 10 errors

Fixes #19480
  • Loading branch information
nyalldawson committed Jul 30, 2018
1 parent 9db6d94 commit 3c8b156c58fbaf42dd9f90ac2c0eb55f343d75b2
Showing with 15 additions and 1 deletion.
  1. +7 −1 src/core/qgsexpressionparser.yy
  2. +8 −0 tests/src/core/testqgsexpression.cpp
@@ -31,6 +31,9 @@
// don't redeclare malloc/free
#define YYINCLUDED_STDLIB_H 1

// maximum number of errors encountered before parser aborts
#define MAX_ERRORS 10

struct expression_parser_context;
#include "qgsexpressionparser.hpp"

@@ -177,7 +180,10 @@ root: expression { parser_ctx->rootNode = $1; }
| error expression
{
delete $2;
yyerrok;
if ( parser_ctx->parserErrors.count() < MAX_ERRORS )
yyerrok;
else
YYABORT;
}
;

@@ -287,6 +287,14 @@ class TestQgsExpression: public QObject
QCOMPARE( exp.parserErrors().first().lastColumn, lastColumn );
}

void max_errors()
{
QgsExpression e( "wkt_geom&#x9;OBJECTID&#x9;id&#x9;a&#x9;b&#x9;c&#x9;d&#x9;e&#x9;f&#x9;g&#x9;h&#x9;i&#x9;j&#x9;k&#x9;l&#x9;m&#x9;n&#x9;o&#x9;p&#x9;q&#x9;r&#x9;" );
QVERIFY( e.hasParserError() );
// want parsing to abort after a maximum of 10 errors
QCOMPARE( e.parserErrors().count(), 10 );
}

void parsing_with_locale()
{
// check that parsing of numbers works correctly even when using some other locale

0 comments on commit 3c8b156

Please sign in to comment.
You can’t perform that action at this time.