Bug 865008 - Search by "ID" never finds any results, r=neil
authorColby Russell <Sevenspade@gmail.com>
Wed, 01 May 2013 16:20:45 -0500
changeset 1663 561155ad5353ceccb7c012d8eb6041bb0e4275a9
parent 1662 35137780b095a630edda6195d4bee6f9b0731baf
child 1666 eb67843ea7022539037e603a204a289faed449d1
push id637
push usersevenspade@gmail.com
push dateWed, 01 May 2013 21:21:18 +0000
reviewersneil
bugs865008
Bug 865008 - Search by "ID" never finds any results, r=neil
resources/content/viewers/dom/dom.js
--- a/resources/content/viewers/dom/dom.js
+++ b/resources/content/viewers/dom/dom.js
@@ -919,33 +919,25 @@ DOMViewer.prototype =
       promptService.alert(window, title, msg);
     }
   },
 
   doFindElementById: function DVr_DoFindElementById(aWalker)
   {
     var re = new RegExp(this.mFindParams[0], "i");
 
-    var node = aWalker.currentNode;
-    if (!node) {
-      return false;
-    }
-
-    if (node.nodeType != Components.interfaces.nsIDOMNode.ELEMENT_NODE) {
-      return false;
-    }
-
-    for (var i = 0; i < node.attributes.length; i++) {
-      var attr = node.attributes[i];
-      if (attr.isId && re.test(attr.nodeValue)) {
-        return true;
-      }
-    }
-
-    return false;
+    // NB: In HTML getAttribute can return null, so we have to check that it's
+    // actually set; if we don't and the search string is "null", implicit
+    // toString conversion means that we'll match on every element without an
+    // ID.  Additionally, for elements without an ID, getAttribute returns an
+    // empty string in XUL (bug 232598), so our check must handle that...
+    return aWalker.currentNode &&
+           aWalker.currentNode.nodeType == nsIDOMNode.ELEMENT_NODE &&
+           aWalker.currentNode.hasAttribute("id") &&
+           re.test(aWalker.currentNode.getAttribute("id"));
   },
 
   doFindElementsByTagName: function DVr_DoFindElementsByTagName(aWalker)
   {
     var re = new RegExp(this.mFindParams[0], "i");
 
     return aWalker.currentNode &&
            aWalker.currentNode.nodeType == nsIDOMNode.ELEMENT_NODE &&