MM-14446: consider subpath when evaluating if url is internal (#946)
* MM-14446: consider subpath when evaluating if url is internal When clicking on an URL with `target=_blank`, the webview decides if it should launch an external browser or a new window within the Electron application. Update this logic to consider the application's configured subpath so as to treat links outside the subpath but on the same domain as external. * fix licensing on new file * fix .eslintrc.json indentation * tweak header eslint rules for specific files
This commit is contained in:

committed by
William Gathoye

parent
6e2b3d7fab
commit
79e020ba43
47
test/specs/utils/util_test.js
Normal file
47
test/specs/utils/util_test.js
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
'use strict';
|
||||
|
||||
import url from 'url';
|
||||
import assert from 'assert';
|
||||
|
||||
import Utils from '../../../src/utils/util';
|
||||
|
||||
describe('Utils', () => {
|
||||
describe('isInternalURL', () => {
|
||||
it('should be false for different hosts', () => {
|
||||
const currentURL = url.parse('http://localhost/team/channel1');
|
||||
const targetURL = url.parse('http://example.com/team/channel2');
|
||||
const basename = '/';
|
||||
assert.equal(Utils.isInternalURL(targetURL, currentURL, basename), false);
|
||||
});
|
||||
|
||||
it('should be false for same hosts, non-matching basename', () => {
|
||||
const currentURL = url.parse('http://localhost/subpath/team/channel1');
|
||||
const targetURL = url.parse('http://localhost/team/channel2');
|
||||
const basename = '/subpath';
|
||||
assert.equal(Utils.isInternalURL(targetURL, currentURL, basename), false);
|
||||
});
|
||||
|
||||
it('should be true for same hosts, matching basename', () => {
|
||||
const currentURL = url.parse('http://localhost/subpath/team/channel1');
|
||||
const targetURL = url.parse('http://localhost/subpath/team/channel2');
|
||||
const basename = '/subpath';
|
||||
assert.equal(Utils.isInternalURL(targetURL, currentURL, basename), true);
|
||||
});
|
||||
|
||||
it('should be true for same hosts, default basename', () => {
|
||||
const currentURL = url.parse('http://localhost/team/channel1');
|
||||
const targetURL = url.parse('http://localhost/team/channel2');
|
||||
const basename = '/';
|
||||
assert.equal(Utils.isInternalURL(targetURL, currentURL, basename), true);
|
||||
});
|
||||
|
||||
it('should be true for same hosts, default basename, empty target path', () => {
|
||||
const currentURL = url.parse('http://localhost/team/channel1');
|
||||
const targetURL = url.parse('http://localhost/');
|
||||
const basename = '/';
|
||||
assert.equal(Utils.isInternalURL(targetURL, currentURL, basename), true);
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user