Bug 1360132 - 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 576905 0f993ff164156e46271c2c249d801404c0396318
parent 576897 1178b701781de2b1a5afb7b7d6b4954a3a7a51ba
child 628344 0b238f9372772584279333de0655e77abc9731f6
push id58518
push userbmo:pbrosset@mozilla.com
push dateFri, 12 May 2017 13:18:24 +0000
reviewerspbro
bugs1360132
milestone55.0a1
Bug 1360132 - 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;
 }