Skip to content

[Bug] Links in hover tooltips show wrong link target on account of empty href attribute #5240

@kleinfreund

Description

@kleinfreund

Reproducible in vscode.dev or in VS Code Desktop?

  • Not reproducible in vscode.dev or VS Code Desktop

Reproducible in the monaco editor playground?

Monaco Editor Playground Link

https://microsoft.github.io/monaco-editor/playground.html?source=v0.55.1#XQAAAAK1BAAAAAAAAABBqQkHQ5NjdMjwa-jY7SIQ9S7DNlzs5W-mwj0fe1ZCDRFc9ws9XQE0SJE1jc2VKxhaLFIw9vEWSxW3yscw7CRL3dbD0yTm9PBkbpAuszLxat513xdup2C2_l1CzjuFyfDT_1lBACVOelNXBZUA1EgQaHyac5LTQwMFzf8GRW99bOIjA2mP9LZTJKWZv9htrlb6JLA-rim0ozyblFbPR16qNJ8fv9N2RdbbCludP_pMVXEuAp9DXjIGO_Z_Nplfk6Dij6nS5wsVArXHYNBjntx20zPjhjMGx7f3fW1bTfiX-_d4kSwcpjjpn__GJtxhLmya8rfmMslFnvTHCf13J4gE3ekNfiWi7OwCeiyC0VLe7sF3uaSyYyTZUzR9yCzdGo0J5EhSuEl3owGJahlyXlQeAXUoz-r7o8I9i4YEZteOtuUB4OEJrnzMaC2nuxRRjkk_x92fNdC5xEo_Sw0HGmhIoW6-0zdY3g21B9peETa2PVaDvm3oklVMkYkqTje_vYWtsly3OEOO0AiMI1NsTLYyPqgbHG5sBQXYqIdkQeLu4QtyQphVTkp49st0-mz-15Q5gVblqi8tIVYNq8i111ps7Cf3nYd95uSksyG8lPWz9egAczXDCMZ4dxQwkxmS8BWCRONsjMIloe-nYREQ3MXh4_MHaDuBnCHfqOdR1hTP0XTrHOM2-UljJxaNO8OYMhGX6CvUr_LLpOXKHcAzR0jYL-QeCXM6X8UE3xTcSbVr7VNJji7u8sHoJH6MSXmAmXdmh8pd_iuwUYxvQkSuTXGRjqKG-UC3Tcx9YH5u-3IXuF3WTdd8s6onS8X_ThVdijR8_7luIOg

Monaco Editor Playground Code

monaco.languages.register({ id: "mySpecialLanguage" });

monaco.languages.registerHoverProvider("mySpecialLanguage", {
	provideHover: function (model, position) {
		return xhr("./playground.html").then(function (res) {
			return {
				range: new monaco.Range(
					1,
					1,
					model.getLineCount(),
					model.getLineMaxColumn(model.getLineCount())
				),
				contents: [
					{ value: "[link](https://google.com)" },
					// ^ only change from the default hover example 
				],
			};
		});
	},
});

monaco.editor.create(document.getElementById("container"), {
	value: "\n\nHover over this text",
	language: "mySpecialLanguage",
});

function xhr(url) {
	var req = null;
	return new Promise(function (c, e) {
		req = new XMLHttpRequest();
		req.onreadystatechange = function () {
			if (req._canceled) {
				return;
			}

			if (req.readyState === 4) {
				if (
					(req.status >= 200 && req.status < 300) ||
					req.status === 1223
				) {
					c(req);
				} else {
					e(req);
				}
				req.onreadystatechange = function () {};
			}
		};

		req.open("GET", url, true);
		req.responseType = "";

		req.send(null);
	}).catch(function () {
		req._canceled = true;
		req.abort();
	});
}

Reproduction Steps

  1. Hover over any of the text in the preview section
  2. Hover over the "link" text in the opened tooltip

Actual (Problematic) Behavior

  • the URL displayed in the desktop browser UI in the bottom left is always the window.location.href on account of the "link" link having href="" (the intended URL is shown via title attribute)
  • Some native browser link interactions like "Right click to open in a new tab" are broken because the href attribute isn't appropriately set to the link target (note, that the playground somehow prevents right clicking on the link, but in a real example, right clicking works)
  • Activating the link via click works, presumably there's some JavaScript using the value of the data-href attribute which does hold the correct link target

Expected Behavior

  • the URL displayed in the desktop browser UI is exactly the link target
  • All native browser link interactions are available
  • Activating the link via click works

Additional Context

It's not clear why this was done but it should be a straightforward fix.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions