[MM-34836] Cleanse URLs of extra slashes on parsing, and add the image proxy case (#1560)
* [MM-34836] Cleanse URLs of extra slashes on parsing, and add the image proxy case * Added unit tests
This commit is contained in:
@@ -40,7 +40,7 @@ function parseURL(inputURL) {
|
||||
return inputURL;
|
||||
}
|
||||
try {
|
||||
return new URL(inputURL);
|
||||
return new URL(inputURL.replace(/([^:]\/)\/+/g, '$1'));
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
|
@@ -136,6 +136,12 @@ const generateNewWindowListener = (getServersFunction, spellcheck) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Image proxy case
|
||||
if (parsedURL.pathname.match(/^\/api\/v[3-4]\/image/)) {
|
||||
shell.openExternal(url);
|
||||
return;
|
||||
}
|
||||
|
||||
if (parsedURL.pathname.match(/^\/help\//)) {
|
||||
// Help links case
|
||||
// continue to open special case internal urls in default browser
|
||||
|
@@ -2,3 +2,4 @@
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import './trusted_origins_test';
|
||||
import './url_test';
|
||||
|
18
test/unit/url_test.js
Normal file
18
test/unit/url_test.js
Normal file
@@ -0,0 +1,18 @@
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
'use strict';
|
||||
|
||||
import assert from 'assert';
|
||||
|
||||
import urlUtils from 'common/utils/url';
|
||||
|
||||
describe('URL', () => {
|
||||
describe('parseURL', () => {
|
||||
it('should remove duplicate slashes in a URL when parsing', () => {
|
||||
const urlWithExtraSlashes = 'https://mattermost.com//sub//path//example';
|
||||
const parsedURL = urlUtils.parseURL(urlWithExtraSlashes);
|
||||
|
||||
assert.strictEqual(parsedURL.toString(), 'https://mattermost.com/sub/path/example');
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user