Skip to content

Commit

Permalink
Remove the ability to pass filters to a global helper.
Browse files Browse the repository at this point in the history
We may revisit this in the future but reducing API change surface for now.
If you need to return raw values from a helper you can use Chunks or the `esc` pragma.
  • Loading branch information
Seth Kinast committed May 12, 2015
1 parent b72bd8f commit eb3ee28
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 27 deletions.
9 changes: 4 additions & 5 deletions lib/dust.js
Original file line number Diff line number Diff line change
Expand Up @@ -901,7 +901,7 @@

Chunk.prototype.helper = function(name, context, bodies, params, auto) {
var chunk = this,
ret, filters;
ret;

// Pre-2.7.1 compat: if auto is undefined, it's an old template. Automatically escape
if (auto === undefined) {
Expand All @@ -918,10 +918,9 @@
if (ret instanceof Chunk) {
return ret;
}
if(typeof params.filters === 'string') {
filters = params.filters.split('|');
}
return chunk.reference(ret, context, auto, filters);
// Currently you cannot pass filters to a helper per Dust working group discussion
// If you needed to unescape filter output you could use the {%esc:s} pragma
return chunk.reference(ret, context, auto);
} catch(err) {
dust.log('Error in helper `' + name + '`: ' + err.message, ERROR);
return chunk.setError(err);
Expand Down
23 changes: 1 addition & 22 deletions test/templates/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -2237,13 +2237,6 @@ return [
expected: "You & I",
message: "helper escapes returned primitives"
},
{
name: "helper filters a primitive",
source: '{@return value="You & I" filters="|s"/}',
context: {},
expected: "You & I",
message: "helper applies filters to returned primitives"
},
{
name: "helper returns a chunk",
source: '{@return value="{hello} & world"/}',
Expand All @@ -2252,26 +2245,12 @@ return [
message: "helper can return a Chunk"
},
{
name: "helper doesn't filter a chunk",
source: '{@return value="{hello} & world" filters="|s"/}',
context: {hello: '<Hello>'},
expected: "&lt;Hello&gt; & world",
message: "helper doesn't apply filters to a Chunk"
},
{
name: "helper filters are affected by pragma",
name: "helper filtering is affected by pragma",
source: '{%esc:s}{@return value="You & I"/}{/esc}',
context: {},
expected: "You & I",
message: "helper applies filter from esc pragma"
},
{
name: "helper filters supercede pragma",
source: '{%esc:s}{@return value="You & I" filters="|h" /}{/esc}',
context: {},
expected: "You &amp; I",
message: "helper filters supercede filter from esc pragma"
},
{
name: "Dust < 2.7.1 compat: helpers escape references",
source: '{#returnLegacy value="You & I" /}',
Expand Down

0 comments on commit eb3ee28

Please sign in to comment.