Permalink
Browse files

Fix static values attributes and methods handling

  • Loading branch information...
1 parent 5253687 commit 30af2f022d48daa211a175d792f3563146f10c4c @Javascipt Javascipt committed Jan 5, 2017
Showing with 28 additions and 4 deletions.
  1. +2 −0 CHANGELOG.md
  2. +4 −4 src/parser.js
  3. +22 −0 tests/parser.js
View
@@ -5,6 +5,8 @@ Changelog
master (unreleased)
----------------
+* Fix handling methods and attributes of static arrays, objects and primitives.
+ Solves the issue [#937](https://github.com/mozilla/nunjucks/issues/937)
3.0.0 (Nov 5 2016)
----------------
View
@@ -968,10 +968,6 @@ var Parser = Object.extend({
}
else if(tok.type === lexer.TOKEN_SYMBOL) {
node = new nodes.Symbol(tok.lineno, tok.colno, tok.value);
-
- if(!noPostfix) {
- node = this.parsePostfix(node);
- }
}
else {
// See if it's an aggregate type, we need to push the
@@ -980,6 +976,10 @@ var Parser = Object.extend({
node = this.parseAggregate();
}
+ if(!noPostfix) {
+ node = this.parsePostfix(node);
+ }
+
if(node) {
return node;
}
View
@@ -299,6 +299,28 @@
expect(n.children[0].typename).to.be('Include');
});
+ it('should accept attributes and methods of static arrays, objects and primitives', function() {
+ expect(function () {
+ parser.parse('{{ ([1, 2, 3]).indexOf(1) }}');
+ }).to.not.throwException();
+
+ expect(function () {
+ parser.parse('{{ [1, 2, 3].length }}');
+ }).to.not.throwException();
+
+ expect(function () {
+ parser.parse('{{ "Some String".replace("S", "$") }}');
+ }).to.not.throwException();
+
+ expect(function () {
+ parser.parse('{{ ({ name : "Khalid" }).name }}');
+ }).to.not.throwException();
+
+ expect(function () {
+ parser.parse('{{ 1.618.toFixed(2) }}');
+ }).to.not.throwException();
+ });
+
it('should parse include tags', function() {
var n = parser.parse('{% include "test.njk" %}');

0 comments on commit 30af2f0

Please sign in to comment.