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 the use of a multi-level object key (e.g. foo.bar) as the key for an index lookup inside non-self-closing tags. #522

Merged
merged 1 commit into from Nov 20, 2014
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
2 changes: 1 addition & 1 deletion lib/parser.js
Expand Up @@ -107,7 +107,7 @@
peg$c42 = { type: "literal", value: "~", description: "\"~\"" },
peg$c43 = function(k) { return ["special", k].concat([['line', line()], ['col', column()]]) },
peg$c44 = { type: "other", description: "identifier" },
peg$c45 = function(p) { var arr = ["path"].concat(p); arr.text = p[1].join('.'); return arr; },
peg$c45 = function(p) { var arr = ["path"].concat(p); arr.text = p[1].join('.').replace(/,line,\d+,col,\d+/g,''); return arr; },
peg$c46 = function(k) { var arr = ["key", k]; arr.text = k; return arr; },
peg$c47 = { type: "other", description: "number" },
peg$c48 = function(n) { return ['literal', n]; },
Expand Down
2 changes: 1 addition & 1 deletion src/dust.pegjs
Expand Up @@ -111,7 +111,7 @@ special "special"
identifier is defined as matching a path or key
---------------------------------------------------------------------------------------------------------------------------------------*/
identifier "identifier"
= p:path { var arr = ["path"].concat(p); arr.text = p[1].join('.'); return arr; }
= p:path { var arr = ["path"].concat(p); arr.text = p[1].join('.').replace(/,line,\d+,col,\d+/g,''); return arr; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the curly's denote a closure of sorts. can we just do a for loop in the array? polyfill map?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we discussed in the meeting today this gets scary when people have variables named "line"

/ k:key { var arr = ["key", k]; arr.text = k; return arr; }

number "number"
Expand Down
12 changes: 12 additions & 0 deletions test/jasmine-test/spec/coreTests.js
Expand Up @@ -676,6 +676,18 @@ var coreTests = [
context: { "test": [[ 1,2,3 ]]},
expected: "1i:0l:3,2i:1l:3,3i:2l:3,",
message: "should test double nested array and . reference: issue #340"
},
{
name: "using a nested key as a reference for array index access",
source: "{#loop.array[key.foo].sub}{.}{/loop.array[key.foo].sub}",
context: {
"loop": {
"array": {"thing": {sub: 1, sap: 2}, "thing2": "bar"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lies!

},
"key": { "foo": "thing" }
},
expected: "1",
message: "should test using a multilevel reference as a key in array access"
}
]
},
Expand Down