Skip to content

Commit

Permalink
Update haml-coffee to fix some broken non boolean attributes.
Browse files Browse the repository at this point in the history
Non boolean values where the key was the same like the value were
wrongly detected as boolean attributes.

In addition empty attributes are allowed also.

This fixes #8.
  • Loading branch information
netzpirat committed Nov 22, 2011
1 parent 921d0c4 commit 7b3dd5f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions lib/js/haml-coffee.js
Original file line number Diff line number Diff line change
Expand Up @@ -693,17 +693,19 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
};

Haml.prototype.parseAttributes = function(exp) {
var attributes, datas, findAttributes, key, match, quoted, value, _ref;
var attributes, bool, datas, findAttributes, key, match, quoted, value, _ref;
attributes = [];
if (exp === void 0) return attributes;
_ref = this.getDataAttributes(exp), exp = _ref[0], datas = _ref[1];
findAttributes = /(?:(\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|"\w+[\w:-]*\w?")\s*=\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[\w@.]+)|(:\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|"\w+[\w:-]*\w?")\s*=>\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[-\w@.()\[\]'"]+)|(\w+[\w:-]*\w?|'\w+[\w:-]*\w?'|'\w+[\w:-]*\w?'):\s*("(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[-\w@.()\[\]'"]+))/g;
while (match = findAttributes.exec(exp)) {
key = (match[1] || match[3] || match[5]).replace(/^:/, '');
value = match[2] || match[4] || match[6];
if (['false', '', '""', "''"].indexOf(value) === -1) {
bool = false;
if (['false', ''].indexOf(value) === -1) {
if (['true'].indexOf(value) !== -1) {
value = "'" + key + "'";
bool = true;
} else if (!value.match(/^("|').*\1$/)) {
if (this.escapeAttributes) {
value = '\'#{ e(' + value + ') }\'';
Expand All @@ -715,7 +717,8 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
if (quoted = key.match(/^("|')(.*)\1$/)) key = quoted[2];
attributes.push({
key: key,
value: value
value: value,
bool: bool
});
}
}
Expand Down Expand Up @@ -760,10 +763,10 @@ require.define("/nodes/haml.js", function (require, module, exports, __dirname,
_ref2 = tokens.attributes;
for (_j = 0, _len2 = _ref2.length; _j < _len2; _j++) {
attribute = _ref2[_j];
if (attribute.key !== attribute.value || this.format !== 'html5') {
tagParts.push("" + attribute.key + "=" + (this.quoteAttributeValue(attribute.value)));
} else {
if (attribute.bool && this.format === 'html5') {
tagParts.push("" + attribute.key);
} else {
tagParts.push("" + attribute.key + "=" + (this.quoteAttributeValue(attribute.value)));
}
}
}
Expand Down

0 comments on commit 7b3dd5f

Please sign in to comment.