Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix url parsing for urls with percentage sign in them #4937

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 13 additions & 2 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 @@ -64,8 +76,7 @@ export class LinkComputer {
// - append / also match domain urls w'o any path notion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you also edit the comment to reflect the code, e.g. remove the listing and mention the explicit equality testing up to the host part.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the comment, lmk what you think

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: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 } });
});
});
});

Expand Down