Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(parser): disallow filters in a chain and inside expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelgj committed Feb 5, 2014
1 parent cc2bad8 commit 5bcea64
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
4 changes: 3 additions & 1 deletion bin/parser_generator_for_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,8 @@ main(arguments) {
"1|nonexistent",
"publicField",
"_privateField",
"'World'|hello"
"'World'|hello",
"1;'World'|hello",
"'World'|hello;1"
]);
}
18 changes: 14 additions & 4 deletions lib/core/parser/dynamic_parser_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ library angular.core.parser.dynamic_parser_impl;

import 'package:angular/core/parser/parser.dart' show ParserBackend;
import 'package:angular/core/parser/lexer.dart';
import 'package:angular/core/parser/syntax.dart';

class DynamicParserImpl {
static Token EOF = new Token(-1, null);
Expand All @@ -18,14 +19,23 @@ class DynamicParserImpl {
}

parseChain() {
while (optional(';'));
bool isChain = false;
while (optional(';')) {
isChain = true;
}
List expressions = [];
while (index < tokens.length) {
if (peek.text == ')' || peek.text == '}' || peek.text == ']') {
error('Unconsumed token ${peek.text}');
}
expressions.add(parseFilter());
while (optional(';'));
var expr = parseFilter();
expressions.add(expr);
while (optional(';')) {
isChain = true;
}
if (isChain && expr is Filter) {
error('cannot have a filter in a chain');
}
}
return (expressions.length == 1)
? expressions.first
Expand Down Expand Up @@ -203,7 +213,7 @@ class DynamicParserImpl {

parsePrimary() {
if (optional('(')) {
var result = parseFilter();
var result = parseExpression();
expect(')');
return result;
} else if (optional('null') || optional('undefined')) {
Expand Down
15 changes: 9 additions & 6 deletions test/core/parser/parser_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -897,12 +897,6 @@ main() {
expect(eval("1|increment:2", filters)).toEqual(3);
});

it('should evaluate grouped filters', () {
scope.name = 'MISKO';
expect(scope.$eval('n = (name|lowercase)')).toEqual('misko');
expect(scope.$eval('n')).toEqual('misko');
});

it('should parse filters', () {
expect(() {
scope.$eval("1|nonexistent");
Expand Down Expand Up @@ -930,6 +924,15 @@ main() {

expect(expression.eval({}, newFilters)).toEqual('Hello, World!');
}));

it('should not allow filters in a chain', () {
expect(() {
parser("1;'World'|hello");
}).toThrow('cannot have a filter in a chain the end of the expression [1;\'World\'|hello]');
expect(() {
parser("'World'|hello;1");
}).toThrow('cannot have a filter in a chain at column 15 in [\'World\'|hello;1]');
});
});
});
}
Expand Down

0 comments on commit 5bcea64

Please sign in to comment.