mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
fix url parsing for urls with percentage sign in them
This commit is contained in:
@@ -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');
|
||||
@@ -64,8 +76,7 @@ export class LinkComputer {
|
||||
// - append / also match domain urls w'o any path notion
|
||||
try {
|
||||
const url = new URL(text);
|
||||
const urlText = decodeURI(url.toString());
|
||||
if (text !== urlText && text + '/' !== urlText) {
|
||||
if (!text.startsWith(baseUrlString(url))) {
|
||||
continue;
|
||||
}
|
||||
} catch (e) {
|
||||
|
||||
@@ -115,6 +115,13 @@ describe('WebLinksAddon', () => {
|
||||
await resetAndHover(5, 1);
|
||||
await evalLinkStateData('http://test:password@example.com/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:password@example.com/some_path?param=1%202%3');
|
||||
await resetAndHover(12, 0);
|
||||
await evalLinkStateData('http://test:password@example.com/some_path?param=1%202%3', { start: { x: 12, y: 1 }, end: { x: 27, y: 2 } });
|
||||
await resetAndHover(5, 1);
|
||||
await evalLinkStateData('http://test:password@example.com/some_path?param=1%202%3', { start: { x: 12, y: 1 }, end: { x: 27, y: 2 } });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user