Bug 1360132 - Escaped tagName with cssEscape in findCssSelector to deal with special chars; r=pbro
MozReview-Commit-ID: CadEDXDYeBV
--- 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;
}