microsoft / microsoft/monaco-editor

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

Open
#5,240 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Monaco Editor Playground reproduction and inspect the hover tooltip link generated from the Markdown contents. Compare its href with the data-href and title values, then verify that the actual link target appears in the browser status bar and that native link actions work.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.