From 8a33ca95a6c39662e765e425cd72a7b2668681e6 Mon Sep 17 00:00:00 2001 From: Nicolas Chevobbe Date: Thu, 7 Aug 2025 15:18:10 +0000 Subject: [PATCH] Bug 1980892 - [devtools] Remove use of InspectorUtils.isCustomElementName on WalkerSearch#_searchSelectors. a=RyanVM. We used to check if the passed query looked like a tag name so we could bail out early, as we'd get those results from _searchIndex. But InspectorUtils.isCustomElementName does match some legitimate selectors, like div.a-b. Let's remove the check on custom element and trigger the search in such case. Original Revision: https://phabricator.services.mozilla.com/D259783 Differential Revision: https://phabricator.services.mozilla.com/D260238 --- devtools/server/actors/utils/walker-search.js | 7 +----- .../tests/browser/browser_inspector-search.js | 24 +++++++++++++++++++ .../tests/browser/inspector-search-data.html | 1 + 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/devtools/server/actors/utils/walker-search.js b/devtools/server/actors/utils/walker-search.js index 5d75e8153e51..a76714335583 100644 --- a/devtools/server/actors/utils/walker-search.js +++ b/devtools/server/actors/utils/walker-search.js @@ -271,12 +271,7 @@ class WalkerSearch { // will lead the same results since it has access to tagnames anyway if ( // regular tagname - query.match(/^[a-z]+$/i) || - // custom element names - InspectorUtils.isCustomElementName( - query, - this.walker.targetActor.window.document.documentElement.namespaceURI - ) + query.match(/^[a-z]+$/i) ) { return; } diff --git a/devtools/server/tests/browser/browser_inspector-search.js b/devtools/server/tests/browser/browser_inspector-search.js index d526e3e8c27e..62125a548cd9 100644 --- a/devtools/server/tests/browser/browser_inspector-search.js +++ b/devtools/server/tests/browser/browser_inspector-search.js @@ -193,6 +193,10 @@ add_task(async function () { { node: inspectee.getElementById("pseudo"), type: "attributeName" }, { node: inspectee.getElementById("arrows"), type: "attributeName" }, { node: inspectee.getElementById("💩"), type: "attributeName" }, + { + node: inspectee.getElementById("with-hyphen"), + type: "attributeName", + }, ], }, { @@ -295,6 +299,26 @@ add_task(async function () { { node: inspectee.querySelector("#arrows"), type: "xpath" }, ], }, + { + desc: "Search using div + id with hyphen", + search: "div#with-hyphen", + expected: [ + { + node: inspectee.querySelector("div#with-hyphen"), + type: "selector", + }, + ], + }, + { + desc: "Search using div + class with hyphen", + search: "div.with-hyphen", + expected: [ + { + node: inspectee.querySelector("div.with-hyphen"), + type: "selector", + }, + ], + }, ]; const assertSearchResults = (searchResults, expectedResults, msg) => { diff --git a/devtools/server/tests/browser/inspector-search-data.html b/devtools/server/tests/browser/inspector-search-data.html index face1e6421a1..4d7bde6c2823 100644 --- a/devtools/server/tests/browser/inspector-search-data.html +++ b/devtools/server/tests/browser/inspector-search-data.html @@ -50,6 +50,7 @@

Heading 4

+
hyphen