Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Abort expression parsing after encountering a maximum of 10 errors
- Loading branch information
Showing
with
15 additions
and
1 deletion.
-
+7
−1
src/core/qgsexpressionparser.yy
-
+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	OBJECTID	id	a	b	c	d	e	f	g	h	i	j	k	l	m	n	o	p	q	r	" ); |
|
|
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 |
|
|