diff --git a/mithril.js b/mithril.js index d18f8189..dd6deabc 100644 --- a/mithril.js +++ b/mithril.js @@ -96,7 +96,7 @@ classes.push(match[2]) } else if (match[3][0] === "[") { var pair = /\[(.+?)(?:=("|'|)(.*?)\2)?\]/.exec(match[3]) - cell.attrs[pair[1]] = pair[3] || (pair[2] ? "" : true) + cell.attrs[pair[1]] = pair[3] || (pair[2] ? "" : "") } } diff --git a/test/mithril.js b/test/mithril.js index bf86f972..775d7ddb 100644 --- a/test/mithril.js +++ b/test/mithril.js @@ -37,6 +37,10 @@ describe("m()", function () { expect(m("[title=bar]")).to.have.deep.property("attrs.title", "bar") }) + it("sets attr without a value as an empty string", function () { + expect(m("[empty]")).to.have.deep.property("attrs.empty", "") + }) + it("sets correct single quoted attr", function () { expect(m("[title=\'bar\']")).to.have.deep.property("attrs.title", "bar") }) diff --git a/tests/mithril-tests.js b/tests/mithril-tests.js index a5042faa..172c6e06 100644 --- a/tests/mithril-tests.js +++ b/tests/mithril-tests.js @@ -11,6 +11,7 @@ test(function () { return m(".foo").attrs.className === "foo" }) test(function () { return m("[title=bar]").tag === "div" }) test(function () { return m("[title=bar]").attrs.title === "bar" }) + test(function () { return m("[empty]").attrs.empty === "" }) test(function () { return m("[title=\'bar\']").attrs.title === "bar" }) test(function () { return m("[title=\"bar\"]").attrs.title === "bar" }) test(function () { return m("div", "test").children[0] === "test" })