Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions addons/addon-web-links/src/WebLinkProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ export class WebLinkProvider implements ILinkProvider {
}
}

function baseUrlString(url: URL): string {
if (url.password && url.username) {
return `${url.protocol}//${url.username}:${url.password}@${url.host}`;
}

if (url.username) {
return `${url.protocol}//${url.username}@${url.host}`;
}

return `${url.protocol}//${url.host}`;
}

export class LinkComputer {
public static computeLink(y: number, regex: RegExp, terminal: Terminal, activate: (event: MouseEvent, uri: string) => void): ILink[] {
const rex = new RegExp(regex.source, (regex.flags || '') + 'g');
Expand All @@ -56,16 +68,11 @@ export class LinkComputer {

// check via URL if the matched text would form a proper url
// NOTE: This outsources the ugly url parsing to the browser.
// To avoid surprising auto expansion from URL we additionally
// check afterwards if the provided string resembles the parsed
// one close enough:
// - decodeURI decode path segement back to byte repr
// to detect unicode auto conversion correctly
// - append / also match domain urls w'o any path notion
// we check if the provided string resembles the URL-parsed one
// up to the end of the domain name (ignoring path and params)
try {
const url = new URL(text);
const urlText = decodeURI(url.toString());
if (text !== urlText && text + '/' !== urlText) {
if (!text.startsWith(baseUrlString(url))) {
continue;
}
} catch (e) {
Expand Down
7 changes: 7 additions & 0 deletions addons/addon-web-links/test/WebLinksAddon.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,13 @@ describe('WebLinksAddon', () => {
await resetAndHover(5, 1);
await evalLinkStateData('http://test:[email protected]/some_path', { start: { x: 12, y: 1 }, end: { x: 13, y: 2 } });
});
it('url encoded params work properly', async () => {
await writeSync(page, '¥¥¥cafe\u0301 http://test:[email protected]/some_path?param=1%202%3');
await resetAndHover(12, 0);
await evalLinkStateData('http://test:[email protected]/some_path?param=1%202%3', { start: { x: 12, y: 1 }, end: { x: 27, y: 2 } });
await resetAndHover(5, 1);
await evalLinkStateData('http://test:[email protected]/some_path?param=1%202%3', { start: { x: 12, y: 1 }, end: { x: 27, y: 2 } });
});
});
});

Expand Down