“Illegal URL” exception when right-clicking anchor with invalid URL and attempting to open it in group
Describe the bug
The “Open link in group” context-menu item for a link offers all the groups you can move a link into. If you do this on a link with an invalid URL, clicking any of the options triggers the notification:
⚠️ Simple Tab Groups
What's wrong...
Please notify the developer by support email with last error logs (button exists at the bottom of the Options page)
Click here to continue...
The debug logs contain this relevant snippet:
{
"message": "Illegal URL: ⟨An illegal URL here⟩",
"stack": [
"createTabsSafe -> background.js:89:42",
"add -> js/tabs.js:220:30",
"async*createMoveTabMenus/</<.onclick< -> background.js:905:41",
"catchFunc/< -> js/utils.js:62:30"
]
}
To Reproduce
This is reproducible for any HTMLAnchorElement link for which link.matches(":link") && (() => { try { new URL(link); return false; } catch { return true; } })() holds true. (This means: any link for which the href getter returns a non-empty string for which the URL constructor, without a second argument, throws; e.g. any link with an invalid host.)
A Meta Stack Exchange bug report about malformed links exhibits this behavior. Minimal reproducible example:
<a href="https://%00">Click</a>
- Render this link as HTML anywhere.
- Right-click it.
- Go through the “Open link in group” menu and click any group.
(For this particular link, the JSON dump would contain "message": "Illegal URL: https://%00").
Expected behavior
The menu item should not be shown at all for such links. The JS condition above is a pretty good test for when to exclude the menu item.
Desktop (please complete the following information):
- OS and version: Arch Linux (linux 5.15.8.arch1-1, gnome-desktop 1:41.2-1)
- Firefox version: 97.0a1
- Simple Tab Groups version: 4.7.2.1
Additional note:
A related Firefox-internal bug has been reported on Bugzilla: bug 1746494.