Skip to content

Commit 37ecb9a

Browse files
authored
Merge pull request #4965 from jerch/fix_4964
allow uppercase in weblinks
2 parents fb867a9 + 10fe249 commit 37ecb9a

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

addons/addon-web-links/src/WebLinkProvider.ts

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,18 @@ export class WebLinkProvider implements ILinkProvider {
4141
}
4242
}
4343

44-
function baseUrlString(url: URL): string {
45-
if (url.password && url.username) {
46-
return `${url.protocol}//${url.username}:${url.password}@${url.host}`;
44+
function isUrl(urlString: string): boolean {
45+
try {
46+
const url = new URL(urlString);
47+
const parsedBase = url.password && url.username
48+
? `${url.protocol}//${url.username}:${url.password}@${url.host}`
49+
: url.username
50+
? `${url.protocol}//${url.username}@${url.host}`
51+
: `${url.protocol}//${url.host}`;
52+
return urlString.toLocaleLowerCase().startsWith(parsedBase.toLocaleLowerCase());
53+
} catch (e) {
54+
return false;
4755
}
48-
49-
if (url.username) {
50-
return `${url.protocol}//${url.username}@${url.host}`;
51-
}
52-
53-
return `${url.protocol}//${url.host}`;
5456
}
5557

5658
export class LinkComputer {
@@ -67,15 +69,7 @@ export class LinkComputer {
6769
const text = match[0];
6870

6971
// check via URL if the matched text would form a proper url
70-
// NOTE: This outsources the ugly url parsing to the browser.
71-
// we check if the provided string resembles the URL-parsed one
72-
// up to the end of the domain name (ignoring path and params)
73-
try {
74-
const url = new URL(text);
75-
if (!text.startsWith(baseUrlString(url))) {
76-
continue;
77-
}
78-
} catch (e) {
72+
if (!isUrl(text)) {
7973
continue;
8074
}
8175

addons/addon-web-links/src/WebLinksAddon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { ILinkProviderOptions, WebLinkProvider } from './WebLinkProvider';
1818
// - final interpunction like ,.!?
1919
// - any sort of brackets <>()[]{} (not spec conform, but often used to enclose urls)
2020
// - unsafe chars from rfc1738: {}|\^~[]`
21-
const strictUrlRegex = /https?:[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;
21+
const strictUrlRegex = /(https?|HTTPS?):[/]{2}[^\s"'!*(){}|\\\^<>`]*[^\s"':,.!?{}|\\\^~\[\]`()<>]/;
2222

2323

2424
function handleLink(event: MouseEvent, uri: string): void {

addons/addon-web-links/test/WebLinksAddon.api.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ describe('WebLinksAddon', () => {
123123
await evalLinkStateData('http://test:password@example.com/some_path?param=1%202%3', { start: { x: 12, y: 1 }, end: { x: 27, y: 2 } });
124124
});
125125
});
126+
127+
// issue #4964
128+
it('uppercase in protocol and host, default ports', async () => {
129+
const data = ` HTTP://EXAMPLE.COM \\r\\n` +
130+
` HTTPS://Example.com \\r\\n` +
131+
` HTTP://Example.com:80 \\r\\n` +
132+
` HTTP://Example.com:80/staysUpper \\r\\n` +
133+
` HTTP://Ab:xY@abc.com:80/staysUpper \\r\\n`;
134+
await writeSync(page, data);
135+
await pollForLinkAtCell(3, 0, `HTTP://EXAMPLE.COM`);
136+
await pollForLinkAtCell(3, 1, `HTTPS://Example.com`);
137+
await pollForLinkAtCell(3, 2, `HTTP://Example.com:80`);
138+
await pollForLinkAtCell(3, 3, `HTTP://Example.com:80/staysUpper`);
139+
await pollForLinkAtCell(3, 4, `HTTP://Ab:xY@abc.com:80/staysUpper`);
140+
});
126141
});
127142

128143
async function testHostName(hostname: string): Promise<void> {

0 commit comments

Comments
 (0)