Skip to content
Open
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
4 changes: 4 additions & 0 deletions app/lib/methods/helpers/ensureSecureProtocol.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ describe('Add the protocol https at the begin of the URL', () => {
const linkWithDoubleSlashAtBegin = '//www.google.com';
expect(ensureSecureProtocol(linkWithDoubleSlashAtBegin)).toBe('https://www.google.com');
});
it('preserves double slashes that are part of the path', () => {
const linkWithDoubleSlashInPath = 'www.google.com/docs//api';
expect(ensureSecureProtocol(linkWithDoubleSlashInPath)).toBe('https://www.google.com/docs//api');
});
it('return the link as original when sent with rocketchat protocol', () => {
const linkRocketChat = 'rocketchat://www.google.com';
expect(ensureSecureProtocol(linkRocketChat)).toBe(linkRocketChat);
Expand Down
2 changes: 1 addition & 1 deletion app/lib/methods/helpers/ensureSecureProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const ensureSecureProtocol = (url: string): string => {
// Check if URL has a protocol by looking for a valid URI scheme (RFC 3986)
if (!url.match(/^[a-zA-Z][a-zA-Z0-9+.-]*:/)) {
return `https://${url.replace('//', '')}`;
return `https://${url.replace(/^\/\//, '')}`;
}
return url;
};
Expand Down