Improved error handling for unclosed tags
diff --git a/lib/src/parse.dart b/lib/src/parse.dart
index fe7f870..4c032f5 100644
--- a/lib/src/parse.dart
+++ b/lib/src/parse.dart
@@ -73,8 +73,11 @@
}
}
- //FIXME assert stack has only one item and error message if not.
- // Add test for this.
+ if (stack.length != 1) {
+ throw new _TemplateException(
+ "Unclosed tag: '${stack.last.name}'.",
+ templateName, source, stack.last.start);
+ }
return stack.last.children;
}
diff --git a/test/mustache_test.dart b/test/mustache_test.dart
index 8e4f686..f0782f4 100644
--- a/test/mustache_test.dart
+++ b/test/mustache_test.dart
@@ -10,6 +10,7 @@
const BAD_TAG_NAME = 'Unless in lenient mode tags may only contain';
const VALUE_NULL = 'Value was null or missing';
const VALUE_MISSING = 'Value was missing';
+const UNCLOSED_TAG = 'Unclosed tag';
Template parse(String source, {bool lenient: false})
=> new Template(source, lenient: lenient);
@@ -311,6 +312,12 @@
var output = t.renderString({"section": {'var': null}});
expect(output, equals('__'));
});
+
+ test('Unclosed section', () {
+ var source = r'{{#section}}foo';
+ var ex = renderFail(source, {"section": {}});
+ expectFail(ex, null, null, UNCLOSED_TAG);
+ });
});
group('Lenient', () {