Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue #222. Code change + new test added to verify proper behavior #223

Merged
merged 1 commit into from Feb 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 4 additions & 16 deletions lib/dust.js
Expand Up @@ -438,24 +438,12 @@ Chunk.prototype.section = function(elem, context, bodies, params) {
// for anonymous functions that did not returns a chunk, truthiness is evaluated based on the return value
//
else if (elem || elem === 0) {
if (body) {
if(context.stack.head && typeof elem === 'object') {
context.stack.head['$idx'] = 0;
context.stack.head['$len'] = 1;
}
chunk = body(this, context.push(elem));
if(context.stack.head && typeof elem === 'object') {
context.stack.head['$idx'] = undefined;
context.stack.head['$len'] = undefined;
}
return chunk;
}
}
// nonexistent, scalar false value, scalar empty string, null,
if (body) return body(this, context.push(elem));
// nonexistent, scalar false value, scalar empty string, null,
// undefined are all falsy
else if (skip) {
} else if (skip) {
return skip(this, context);
}
}
return this;
};

Expand Down
7 changes: 7 additions & 0 deletions test/jasmine-test/spec/coreTests.js
Expand Up @@ -573,6 +573,13 @@ var coreTests = [
expected: "0Moe 1Larry 2Curly ",
message: "test array reference $idx/$len {#.} section case"
},
{
name: "array reference $idx/$len not changed in nested object",
source: "{#results}{#info}{$idx}{name}-{$len} {/info}{/results}",
context: { results: [ {info: {name: "Steven"}  },  {info: {name: "Richard"} } ]  },
expected: "0Steven-2 1Richard-2 ",
message: "test array reference $idx/$len not changed in nested object"
},
{
name: "array reference $idx/$len nested loops",
source: "{#A}A loop:{$idx}-{$len},{#B}B loop:{$idx}-{$len}C[0]={.C[0]} {/B}A loop trailing: {$idx}-{$len}{/A}",
Expand Down