Skip to content

Commit

Permalink
Fixes mootools#2247.
Browse files Browse the repository at this point in the history
This fixes a nasty regression that custom attributes set by HTML text
(e.g. innerHTML) would previously be considered `expando` and therefore
thought to have been considered a fake attribute. Therefore, we didn't
return the value.

This fix relies now on outerHTML to check for the existence of the
attribute. Keep in mind this also fixes the previous bug of returning
custom functions since any new `el.attribute =` are not shown in
outerHTML.

PASSED: IE6-9.
  • Loading branch information
ibolmo committed Jan 24, 2012
1 parent fc3595d commit d0208f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Source/Element/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,9 @@ Element.implement({
} else {
if (value == null){
this.removeAttribute(name);
/* <ltIE9> */
if (pollutesGetAttribute) delete attributeWhiteList[name];
/* </ltIE9> */
} else {
this.setAttribute(name, value);
/* <ltIE9> */
Expand All @@ -627,8 +630,9 @@ Element.implement({
if (getter) return getter(this);
/* <ltIE9> */
if (pollutesGetAttribute && !attributeWhiteList[name]){
var attr = this.getAttributeNode(name);
if (!attr || attr.expando) return null;
var outer = this.outerHTML, i = outer.indexOf(name);
if ((i < 0) || (i > outer.indexOf('><'))) return null;
attributeWhiteList[name] = true;
}
/* </ltIE9> */
var result = Slick.getAttribute(this, name);
Expand Down
14 changes: 14 additions & 0 deletions Specs/1.4client/Element/Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,20 @@ describe('Element', function(){
expect(div.getProperty('random')).toEqual('attribute');
});

it('should get custom attributes in html', function(){
var div = new Element('div', {html: '<div data-load="test"></div>'}).getFirst();
expect(div.get('data-load')).toEqual('test');

div = new Element('div', {html: '<div data-custom></div>'}).getFirst();
expect(div.get('data-custom')).toEqual('');

div = new Element('div', {html: '<div data-custom="test"><a data-custom="other"></a></div>'}).getFirst();
expect(div.get('data-custom')).toEqual('test');

div = new Element('div', {html: '<div><a data-custom="other"></a></div>'}).getFirst();
expect(div.get('data-custom')).toEqual(null);
});

});

describe('Element.set', function(){
Expand Down

0 comments on commit d0208f9

Please sign in to comment.