Skip to content

Commit

Permalink
Merge branch '2.x'
Browse files Browse the repository at this point in the history
* 2.x:
  Bump version to 2.5.0-dev.2.
  Update version in Changelog, too.
  Release 2.4.1.
  Backport not escaping SafeString; it's a bug.
  Update changelog.
  Merge pull request #701 from legutierr/master
  Merge pull request #623 from atian25/filters-escape
  Throw an error if a block is defined multiple times. Refs #696.
  Update changelog.
  Grammar fixes.
  Merge pull request #691 from dkebler/file-ext
  Update changelog.
  Merge branch 't576'
  • Loading branch information
carljm committed Mar 17, 2016
2 parents 50fabaa + 735390b commit 2c951d9
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 24 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Changelog
2.x (unreleased)
----------------


2.4.1 (Mar 17 2016)
-------------------

* Don't double-escape. Thanks legutierr. Merge of
[#701](https://github.com/mozilla/nunjucks/pull/701).

Expand All @@ -45,6 +49,7 @@ Changelog

2.4.0 (Mar 10 2016)
-------------------
* Fix: [Breaking Change] filter.escape should not escape SafeString(#168).

* Allow retrieving boolean-false as a global. Thanks Marius Büscher. Merge of
[#694](https://github.com/mozilla/nunjucks/pull/694).
Expand Down
7 changes: 3 additions & 4 deletions browser/nunjucks-slim.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Browser bundle of nunjucks 2.4.0 (slim, only works with precompiled templates) */
/*! Browser bundle of nunjucks 2.4.1 (slim, only works with precompiled templates) */
var nunjucks =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
Expand Down Expand Up @@ -1529,9 +1529,8 @@ var nunjucks =
},

escape: function(str) {
if(typeof str === 'string' ||
str instanceof r.SafeString) {
return lib.escape(str);
if(typeof str === 'string') {
return r.markSafe(lib.escape(str));
}
return str;
},
Expand Down
4 changes: 2 additions & 2 deletions browser/nunjucks-slim.min.js

Large diffs are not rendered by default.

49 changes: 35 additions & 14 deletions browser/nunjucks.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Browser bundle of nunjucks 2.4.0 */
/*! Browser bundle of nunjucks 2.4.1 */
var nunjucks =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
Expand Down Expand Up @@ -1884,7 +1884,6 @@ var nunjucks =
compileFilter: function(node, frame) {
var name = node.name;
this.assertType(name, nodes.Symbol);

this.emit('env.getFilter("' + name.value + '").call(context, ');
this._compileAggregate(node.args, frame);
this.emit(')');
Expand Down Expand Up @@ -1942,11 +1941,9 @@ var nunjucks =
this.emitLine(';');
}
else {
this.emitLine(ids.join(' = ') + ' = (function() {');
this.emitLine('var output = "";');
this.emit(ids.join(' = ') + ' = ');
this.compile(node.body, frame);
this.emitLine('return output;');
this.emitLine('})();');
this.emitLine(';');
}

lib.each(node.targets, function(target, i) {
Expand Down Expand Up @@ -2458,6 +2455,16 @@ var nunjucks =
this.compileLiteral(node, frame);
},

compileCapture: function(node, frame) {
this.emitLine('(function() {');
this.emitLine('var output = "";');
this.withScopedSyntax(function () {
this.compile(node.body, frame);
});
this.emitLine('return output;');
this.emitLine('})()');
},

compileOutput: function(node, frame) {
var children = node.children;
for(var i=0, l=children.length; i<l; i++) {
Expand Down Expand Up @@ -2503,11 +2510,18 @@ var nunjucks =

this.inBlock = true;

var blockNames = [];

var i, name, block, blocks = node.findAll(nodes.Block);
for (i = 0; i < blocks.length; i++) {
block = blocks[i];
name = block.name.value;

if (blockNames.indexOf(name) !== -1) {
throw new Error('Block "' + name + '" defined more than once.');
}
blockNames.push(name);

this.emitFuncBegin('b_' + name);

var tmpFrame = new Frame();
Expand Down Expand Up @@ -3095,7 +3109,11 @@ var nunjucks =
tag.colno);
}
else {
node.body = this.parseUntilBlocks('endset');
node.body = new nodes.Capture(
tag.lineno,
tag.colno,
this.parseUntilBlocks('endset')
);
node.value = null;
this.advanceAfterBlockEnd();
}
Expand Down Expand Up @@ -3609,7 +3627,11 @@ var nunjucks =
var args = this.parseFilterArgs(name);

this.advanceAfterBlockEnd(filterTok.value);
var body = this.parseUntilBlocks('endfilter');
var body = new nodes.Capture(
name.lineno,
name.colno,
this.parseUntilBlocks('endfilter')
);
this.advanceAfterBlockEnd();

var node = new nodes.Filter(
Expand All @@ -3619,9 +3641,7 @@ var nunjucks =
new nodes.NodeList(
name.lineno,
name.colno,
// Body is a NodeList with an Output node as a child,
// need to strip those
body.children[0].children.concat(args)
[body].concat(args)
)
);

Expand Down Expand Up @@ -4508,6 +4528,7 @@ var nunjucks =
var Include = Node.extend('Include', { fields: ['template', 'ignoreMissing'] });
var Set = Node.extend('Set', { fields: ['targets', 'value'] });
var Output = NodeList.extend('Output');
var Capture = Node.extend('Capture', { fields: ['body'] });
var TemplateData = Literal.extend('TemplateData');
var UnaryOp = Node.extend('UnaryOp', { fields: ['target'] });
var BinOp = Node.extend('BinOp', { fields: ['left', 'right'] });
Expand Down Expand Up @@ -4643,6 +4664,7 @@ var nunjucks =
Pair: Pair,
Dict: Dict,
Output: Output,
Capture: Capture,
TemplateData: TemplateData,
If: If,
IfAsync: IfAsync,
Expand Down Expand Up @@ -5425,9 +5447,8 @@ var nunjucks =
},

escape: function(str) {
if(typeof str === 'string' ||
str instanceof r.SafeString) {
return lib.escape(str);
if(typeof str === 'string') {
return r.markSafe(lib.escape(str));
}
return str;
},
Expand Down
8 changes: 4 additions & 4 deletions browser/nunjucks.min.js

Large diffs are not rendered by default.

0 comments on commit 2c951d9

Please sign in to comment.