Fix corner case with triple mustache tags
diff --git a/lib/src/parser.dart b/lib/src/parser.dart
index c202eff..2f6a119 100644
--- a/lib/src/parser.dart
+++ b/lib/src/parser.dart
@@ -348,9 +348,14 @@
// A sigil is the character which identifies which sort of tag it is,
// i.e. '#', '/', or '>'.
// Variable tags and triple mustache tags don't have a sigil.
- TagType tagType = _peek().type == TokenType.sigil
- ? tagTypeFromString(_read().value)
- : (open.value == '{{{' ? TagType.tripleMustache : TagType.variable);
+ TagType tagType;
+ if (open.value == '{{{') {
+ tagType = TagType.tripleMustache;
+ } else if (_peek().type == TokenType.sigil) {
+ tagType = tagTypeFromString(_read().value);
+ } else {
+ tagType = TagType.variable;
+ }
checkEof();
diff --git a/test/mustache_test.dart b/test/mustache_test.dart
index d55c5be..cdfdad6 100644
--- a/test/mustache_test.dart
+++ b/test/mustache_test.dart
@@ -285,7 +285,6 @@
test('Bad tag name, open section', () {
var source = r'{{#section$%$^%}}_{{var}}_{{/section}}';
var ex = renderFail(source, {"section": {"var": "bob"}});
- print(ex);
expectFail(ex, null, null, BAD_TAG_NAME);
});
diff --git a/test/parser_test.dart b/test/parser_test.dart
index 9096369..3d53902 100644
--- a/test/parser_test.dart
+++ b/test/parser_test.dart
@@ -3,6 +3,7 @@
import 'package:mustache/src/node.dart';
import 'package:mustache/src/parser.dart';
import 'package:mustache/src/scanner.dart';
+import 'package:mustache/src/template_exception.dart';
import 'package:mustache/src/token.dart';
main() {
@@ -225,6 +226,28 @@
expect(nodes[1].children.first, new TextNode('-', 21, 22));
});
+ test('corner case strict', () {
+ var source = "{{{ #foo }}} {{{ /foo }}}";
+ var parser = new Parser(source, 'foo', '{{ }}', lenient: false);
+ try {
+ var nodes = parser.parse();
+ fail('Should fail.');
+ } catch (e) {
+ expect(e is TemplateException, isTrue);
+ }
+ });
+
+ test('corner case lenient', () {
+ var source = "{{{ #foo }}} {{{ /foo }}}";
+ var parser = new Parser(source, 'foo', '{{ }}', lenient: true);
+ var nodes = parser.parse();
+ expect(nodes, orderedEquals([
+ new VariableNode('#foo', 0, 12, escape: false),
+ new TextNode(' ', 12, 13),
+ new VariableNode('/foo', 13, 25, escape: false)
+ ]));
+ });
+
});
}
\ No newline at end of file