Skip to content

Commit 5bcea64

Browse files
committed
fix(parser): disallow filters in a chain and inside expressions
1 parent cc2bad8 commit 5bcea64

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

bin/parser_generator_for_spec.dart

+3-1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,8 @@ main(arguments) {
225225
"1|nonexistent",
226226
"publicField",
227227
"_privateField",
228-
"'World'|hello"
228+
"'World'|hello",
229+
"1;'World'|hello",
230+
"'World'|hello;1"
229231
]);
230232
}

lib/core/parser/dynamic_parser_impl.dart

+14-4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ library angular.core.parser.dynamic_parser_impl;
22

33
import 'package:angular/core/parser/parser.dart' show ParserBackend;
44
import 'package:angular/core/parser/lexer.dart';
5+
import 'package:angular/core/parser/syntax.dart';
56

67
class DynamicParserImpl {
78
static Token EOF = new Token(-1, null);
@@ -18,14 +19,23 @@ class DynamicParserImpl {
1819
}
1920

2021
parseChain() {
21-
while (optional(';'));
22+
bool isChain = false;
23+
while (optional(';')) {
24+
isChain = true;
25+
}
2226
List expressions = [];
2327
while (index < tokens.length) {
2428
if (peek.text == ')' || peek.text == '}' || peek.text == ']') {
2529
error('Unconsumed token ${peek.text}');
2630
}
27-
expressions.add(parseFilter());
28-
while (optional(';'));
31+
var expr = parseFilter();
32+
expressions.add(expr);
33+
while (optional(';')) {
34+
isChain = true;
35+
}
36+
if (isChain && expr is Filter) {
37+
error('cannot have a filter in a chain');
38+
}
2939
}
3040
return (expressions.length == 1)
3141
? expressions.first
@@ -203,7 +213,7 @@ class DynamicParserImpl {
203213

204214
parsePrimary() {
205215
if (optional('(')) {
206-
var result = parseFilter();
216+
var result = parseExpression();
207217
expect(')');
208218
return result;
209219
} else if (optional('null') || optional('undefined')) {

test/core/parser/parser_spec.dart

+9-6
Original file line numberDiff line numberDiff line change
@@ -897,12 +897,6 @@ main() {
897897
expect(eval("1|increment:2", filters)).toEqual(3);
898898
});
899899

900-
it('should evaluate grouped filters', () {
901-
scope.name = 'MISKO';
902-
expect(scope.$eval('n = (name|lowercase)')).toEqual('misko');
903-
expect(scope.$eval('n')).toEqual('misko');
904-
});
905-
906900
it('should parse filters', () {
907901
expect(() {
908902
scope.$eval("1|nonexistent");
@@ -930,6 +924,15 @@ main() {
930924

931925
expect(expression.eval({}, newFilters)).toEqual('Hello, World!');
932926
}));
927+
928+
it('should not allow filters in a chain', () {
929+
expect(() {
930+
parser("1;'World'|hello");
931+
}).toThrow('cannot have a filter in a chain the end of the expression [1;\'World\'|hello]');
932+
expect(() {
933+
parser("'World'|hello;1");
934+
}).toThrow('cannot have a filter in a chain at column 15 in [\'World\'|hello;1]');
935+
});
933936
});
934937
});
935938
}

0 commit comments

Comments
 (0)