commit c8a8a73cb865b57cefa24da7ab6f34c097451500
parent 6c19a7a0331d63b090e16c77445c5e59c98c93c0
Author: Nicolas Chevobbe <nchevobbe@mozilla.com>
Date: Tue, 21 Oct 2025 10:13:35 +0000
Bug 1995459 - [devtools] Don't escape id passed to WalkerFront#getIdrefNode. r=devtools-reviewers,ochameau.
The actor uses getElementById, so we don't need to escape the id.
Differential Revision: https://phabricator.services.mozilla.com/D269345
Diffstat:
4 files changed, 41 insertions(+), 7 deletions(-)
diff --git a/devtools/client/inspector/markup/markup.js b/devtools/client/inspector/markup/markup.js
@@ -1374,7 +1374,11 @@ MarkupView.prototype = {
} else if (type == "idref") {
// Select the node in the same document.
nodeFront.walkerFront
- .getIdrefNode(nodeFront, CSS.escape(link))
+ .getIdrefNode(
+ nodeFront,
+ // No need to escape the id, the server getIdrefNode uses getElementById
+ link
+ )
.then(node => {
if (!node) {
this.emitForTests("idref-attribute-link-failed");
diff --git a/devtools/client/inspector/markup/test/browser_markup_links_01.js b/devtools/client/inspector/markup/test/browser_markup_links_01.js
@@ -60,6 +60,15 @@ const TEST_DATA = [
],
},
{
+ selector: `label[for="${CSS.escape("3d")}"]`,
+ attributes: [
+ {
+ attributeName: "for",
+ links: [{ type: "idref", value: "3d" }],
+ },
+ ],
+ },
+ {
selector: "output",
attributes: [
{
diff --git a/devtools/client/inspector/markup/test/browser_markup_links_07.js b/devtools/client/inspector/markup/test/browser_markup_links_07.js
@@ -48,14 +48,22 @@ add_task(async function () {
linkEl = editor.attrElements.get("for").querySelector(".link");
info("Follow link with middle-click, wait for new node to be selected.");
- await followLinkWaitForNewNode(linkEl, false, inspector);
+ await followLinkWaitForNewNode(linkEl, false, inspector, "name");
- // We have to re-select the label as the link switched the currently selected
- // node.
+ // We have to re-select the label as the link switched the currently selected node.
await selectNode("label", inspector);
info("Follow link with ctrl/meta-click, wait for new node to be selected.");
- await followLinkWaitForNewNode(linkEl, true, inspector);
+ await followLinkWaitForNewNode(linkEl, true, inspector, "name");
+
+ info("Find the label for the element whose id starts with a number");
+ await selectNode(`label[for="${CSS.escape("3d")}"]`, inspector);
+ ({ editor } = await getContainerForSelector(
+ `label[for="${CSS.escape("3d")}"]`,
+ inspector
+ ));
+ linkEl = editor.attrElements.get("for").querySelectorAll(".link")[0];
+ await followLinkWaitForNewNode(linkEl, true, inspector, "3d");
info("Select a node with an invalid IDREF attribute");
await selectNode("output", inspector);
@@ -144,13 +152,22 @@ async function followLinkWaitForTab(linkEl, isMetaClick, expectedTabURI) {
gBrowser.removeTab(target);
}
-async function followLinkWaitForNewNode(linkEl, isMetaClick, inspector) {
+async function followLinkWaitForNewNode(
+ linkEl,
+ isMetaClick,
+ inspector,
+ expectedSelectedNodeId
+) {
const onSelection = inspector.selection.once("new-node-front");
performMouseDown(linkEl, isMetaClick);
await onSelection;
ok(true, "A new node was selected");
- is(inspector.selection.nodeFront.id, "name", "The right node was selected");
+ is(
+ inspector.selection.nodeFront.id,
+ expectedSelectedNodeId,
+ "The right node was selected"
+ );
}
async function followLinkNoNewNode(linkEl, isMetaClick, inspector) {
diff --git a/devtools/client/inspector/markup/test/doc_markup_links.html b/devtools/client/inspector/markup/test/doc_markup_links.html
@@ -17,6 +17,10 @@
<input id="message" type="text" />
</p>
<p>
+ <label for="3d" id="for-three-d">3d</label>
+ <input id="3d" type="text" />
+ </p>
+ <p>
<button>Send message</button>
</p>
<output form="message-form" for="name message invalid">Thank you for your message!</output>