diff --git a/tags/for.js b/tags/for.js index b1fb1ccc4..e5a9567f8 100644 --- a/tags/for.js +++ b/tags/for.js @@ -43,7 +43,7 @@ module.exports = function (liquid) { if (_.isString(collection) && collection.length > 0) { collection = [collection] } else if (_.isObject(collection)) { - collection = Object.keys(collection) + collection = Object.keys(collection).map((key) => [key, collection[key]]) } } if (!Array.isArray(collection) || !collection.length) { diff --git a/test/tags/for.js b/test/tags/for.js index 265f12b1e..592cac2cb 100644 --- a/test/tags/for.js +++ b/test/tags/for.js @@ -28,9 +28,9 @@ describe('tags/for', function () { }) it('should support object', function () { - var src = '{%for key in obj%}{{key}}-{%else%}b{%endfor%}' + var src = '{%for item in obj%}{{item[0]}},{{item[1]}}-{%else%}b{%endfor%}' return expect(liquid.parseAndRender(src, ctx)) - .to.eventually.equal('foo-coo-') + .to.eventually.equal('foo,bar-coo,haa-') }) describe('scope', function () {