#114 ✓resolved
nickg

PATCH: Node.setAttribute incorrectly restricts 'value' to be only strings

Reported by nickg | March 15th, 2010 @ 07:05 PM | in 1.2.x

Looks like I have the magic touch today.

http://github.com/client9/env-js/commit/4cd9fa12fd7d1ea868429be605f...

The following:

somenode.setAttribute('foo', 0);
somenode.setAttribute('foo', null);

are valid constructs, and set the attribute to the string-value of the argument. However they semi-silently get ignored right now. I found this since numeric values are used in the Image constructor and get passed to setAttribute.

in src/dom/element.js around line 49, we have:

            // test for exceptions                                                                                                               
            if (__ownerDocument__(this).implementation.errorChecking) {
                // throw Exception if Attribute is readonly                                                                                      
                if (attr._readonly) {
                    throw(new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR));
                }
                // throw Exception if the value string contains an illegal character                                                             
                if (!__isValidString__(value)) {
                    throw(new DOMException(DOMException.INVALID_CHARACTER_ERR));
                }
            }

            // assign values to properties (and aliases)                                                                                         
            attr.value     = value + '';

So at the end, we make sure value is a string. But right above, we do a isValidString check on the raw value, not the string value. If a non-string is passed in, this explodes.

setting value = value + '' uptop will solve this (committed).

This one is a blocker for me. Unit tests will be in forthcoming commit for Image.

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

a javascript browser environment

People watching this ticket

Pages