Permalink
Browse files

Merge pull request #80 from sdumitriu/issue-1431

Fix an issue where `writeAttribute` tries to set an attribute named `undefined` in certain cases. [#1431 state:resolved]
  • Loading branch information...
savetheclocktower committed Nov 2, 2012
2 parents d017062 + 4a22a52 commit b0b9c93f85547431e4a62e4cb860b5acbdceb963
Showing with 22 additions and 4 deletions.
  1. +1 −1 src/prototype/dom/dom.js
  2. +21 −3 test/unit/dom_test.js
View
@@ -2353,7 +2353,7 @@
name = table.names[attr] || attr;
value = attributes[attr];
if (table.values[attr])
- name = table.values[attr](element, value);
+ name = table.values[attr](element, value) || name;
if (value === false || value === null)
element.removeAttribute(name);
else if (value === true)
View
@@ -1090,18 +1090,36 @@ new Test.Unit.Runner({
testElementWriteAttributeWithBooleans: function() {
var input = $('write_attribute_input'),
- select = $('write_attribute_select'),
- checkbox = $('write_attribute_checkbox'),
- checkedCheckbox = $('write_attribute_checked_checkbox');
+ select = $('write_attribute_select');
this.assert( input. writeAttribute('readonly'). hasAttribute('readonly'));
this.assert(!input. writeAttribute('readonly', false). hasAttribute('readonly'));
this.assert( input. writeAttribute('readonly', true). hasAttribute('readonly'));
this.assert(!input. writeAttribute('readonly', null). hasAttribute('readonly'));
this.assert( input. writeAttribute('readonly', 'readonly').hasAttribute('readonly'));
this.assert( select. writeAttribute('multiple'). hasAttribute('multiple'));
this.assert( input. writeAttribute('disabled'). hasAttribute('disabled'));
+ },
+ testElementWriteAttributeForCheckbox: function() {
+ var checkbox = $('write_attribute_checkbox'),
+ checkedCheckbox = $('write_attribute_checked_checkbox');
this.assert( checkbox. writeAttribute('checked'). checked);
+ this.assert( checkbox. writeAttribute('checked'). hasAttribute('checked'));
+ this.assertEqual('checked', checkbox.writeAttribute('checked').getAttribute('checked'));
+ this.assert(!checkbox. writeAttribute('checked'). hasAttribute('undefined'));
+ this.assert( checkbox. writeAttribute('checked', true). checked);
+ this.assert( checkbox. writeAttribute('checked', true). hasAttribute('checked'));
+ this.assert( checkbox. writeAttribute('checked', 'checked'). checked);
+ this.assert( checkbox. writeAttribute('checked', 'checked'). hasAttribute('checked'));
+ this.assert(!checkbox. writeAttribute('checked', null). checked);
+ this.assert(!checkbox. writeAttribute('checked', null). hasAttribute('checked'));
+ this.assert(!checkbox. writeAttribute('checked', true). hasAttribute('undefined'));
this.assert(!checkedCheckbox.writeAttribute('checked', false). checked);
+ this.assert(!checkbox. writeAttribute('checked', false). hasAttribute('checked'));
+ },
+ testElementWriteAttributeForStyle: function() {
+ var element = Element.extend(document.body.appendChild(document.createElement('p')));
+ this.assert( element. writeAttribute('style', 'color: red'). hasAttribute('style'));
+ this.assert(!element. writeAttribute('style', 'color: red'). hasAttribute('undefined'));
},
testElementWriteAttributeWithIssues: function() {

0 comments on commit b0b9c93

Please sign in to comment.