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
@@ -8,4 +8,22 @@ function getDomain(inputURL) {
|
||||
return `${parsedURL.protocol}//${parsedURL.host}`;
|
||||
}
|
||||
|
||||
export default {getDomain};
|
||||
// isInternalURL determines if the target url is internal to the application.
|
||||
// - currentURL is the current url inside the webview
|
||||
// - basename is the global export from the Mattermost application defining the subpath, if any
|
||||
function isInternalURL(targetURL, currentURL, basename = '/') {
|
||||
if (targetURL.host !== currentURL.host) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(targetURL.pathname || '/').startsWith(basename)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
export default {
|
||||
getDomain,
|
||||
isInternalURL,
|
||||
};
|
||||
|
Reference in New Issue
Block a user