From a9c70bcc1c6c70cad118f0028ced3e532bddb196 Mon Sep 17 00:00:00 2001 From: Ben Alpert Date: Tue, 4 Jun 2013 19:21:38 -0700 Subject: [PATCH] getDOMNodeID: Don't return .id on random objects If you defined a global named `id` (a horrible name, I know) then getDOMNodeID(window) would return that object. Since only DOM nodes can have IDs, this should be a noop change otherwise. Test Plan: Verified that document.documentElement and document.body both support getAttributeNode properly in latest Chrome and in IE8. --- src/dom/getDOMNodeID.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/dom/getDOMNodeID.js b/src/dom/getDOMNodeID.js index 1f4abe6974..f9632d8de5 100644 --- a/src/dom/getDOMNodeID.js +++ b/src/dom/getDOMNodeID.js @@ -21,8 +21,9 @@ /** * Accessing "id" or calling getAttribute('id') on a form element can return its - * control whose name or ID is "id". However, not all DOM nodes support - * `getAttributeNode` (document - which is not a form) so that is checked first. + * control whose name or ID is "id". All DOM nodes support `getAttributeNode` + * but this can also get called on other objects so just return '' if we're + * given something other than a DOM node (such as window). * * @param {DOMElement|DOMWindow|DOMDocument} domNode DOM node. * @returns {string} ID of the supplied `domNode`. @@ -32,7 +33,7 @@ function getDOMNodeID(domNode) { var attributeNode = domNode.getAttributeNode('id'); return attributeNode && attributeNode.value || ''; } else { - return domNode.id || ''; + return ''; } }