bug1360132 - 'Escaped tagName with cssEscape in findCssSelector to deal with special chars.' r=pbro draft
authornbeltran14 <nbeltran14@mail.wou.edu>
Thu, 11 May 2017 20:03:35 +0200
changeset 576383 f7150f138ababf90d351efe02c938cef7a89a104
parent 576334 3b96f277325747fe668ca8cd896d2f581238e4ee
child 628188 634deebd57d108bad99636a8e2d4ca7101f53618
push id58350
push userbmo:nbeltran14@mail.wou.edu
push dateThu, 11 May 2017 18:05:07 +0000
reviewerspbro
bugs1360132
milestone55.0a1
bug1360132 - 'Escaped tagName with cssEscape in findCssSelector to deal with special chars.' r=pbro MozReview-Commit-ID: CadEDXDYeBV
toolkit/modules/css-selector.js
--- a/toolkit/modules/css-selector.js
+++ b/toolkit/modules/css-selector.js
@@ -82,17 +82,17 @@ const findCssSelector = function(ele) {
     for (let i = 0; i < ele.classList.length; i++) {
       // Is this className unique by itself?
       selector = "." + cssEscape(ele.classList.item(i));
       matches = document.querySelectorAll(selector);
       if (matches.length === 1) {
         return selector;
       }
       // Maybe it's unique with a tag name?
-      selector = tagName + selector;
+      selector = cssEscape(tagName) + selector;
       matches = document.querySelectorAll(selector);
       if (matches.length === 1) {
         return selector;
       }
       // Maybe it's unique using a tag name and nth-child
       index = positionInNodeList(ele, ele.parentNode.children) + 1;
       selector = selector + ":nth-child(" + index + ")";
       matches = document.querySelectorAll(selector);
@@ -102,13 +102,13 @@ const findCssSelector = function(ele) {
     }
   }
 
   // Not unique enough yet.  As long as it's not a child of the document,
   // continue recursing up until it is unique enough.
   if (ele.parentNode !== document) {
     index = positionInNodeList(ele, ele.parentNode.children) + 1;
     selector = findCssSelector(ele.parentNode) + " > " +
-      tagName + ":nth-child(" + index + ")";
+      cssEscape(tagName) + ":nth-child(" + index + ")";
   }
 
   return selector;
 }