From d4060d0d59f2462dd90f3438de29d8d269da732e Mon Sep 17 00:00:00 2001 From: lip-d Date: Sat, 17 Feb 2018 18:15:14 +0900 Subject: [PATCH 1/3] Fixed issue: clicking on a file:// protocol path does not open windows explorer since version 3.5.0 #579 --- src/browser/components/MattermostView.jsx | 28 ++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/browser/components/MattermostView.jsx b/src/browser/components/MattermostView.jsx index 8393d3c7..d95aa091 100644 --- a/src/browser/components/MattermostView.jsx +++ b/src/browser/components/MattermostView.jsx @@ -157,7 +157,33 @@ const MattermostView = createReactClass({ console.warn(message); break; case 2: - console.error(message); + let match = e.message.match(/Not allowed to load local resource:\s*(.+)/); + let resURL = ""; + let isNetworkDrive = false; + + if (match != null) { + if (match.length == 2) { + resURL = match[1]; + + let u = url.parse(resURL); + + // Is it on a network drive? + if (u.protocol === 'file:' && u.host) { + isNetworkDrive = true; + } + } + } + + // Network drive: Should be allowed. + if (isNetworkDrive) { + if (!shell.openExternal(decodeURI(resURL))) { + console.log(`[${this.props.name}] shell.openExternal failed: ${resURL}`); + } + } + // Local drive such as 'C:\Windows': Should not be allowed. + else { + console.error(message); + } break; default: console.log(message); From dcc7819dea7fad0dcbb8bb67be6463be7ef57ba0 Mon Sep 17 00:00:00 2001 From: lip-d Date: Wed, 21 Feb 2018 19:57:15 +0900 Subject: [PATCH 2/3] implemented all the review comments --- src/browser/components/MattermostView.jsx | 47 +++++++++++------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/src/browser/components/MattermostView.jsx b/src/browser/components/MattermostView.jsx index d95aa091..768b4964 100644 --- a/src/browser/components/MattermostView.jsx +++ b/src/browser/components/MattermostView.jsx @@ -157,31 +157,14 @@ const MattermostView = createReactClass({ console.warn(message); break; case 2: - let match = e.message.match(/Not allowed to load local resource:\s*(.+)/); - let resURL = ""; - let isNetworkDrive = false; - - if (match != null) { - if (match.length == 2) { - resURL = match[1]; - - let u = url.parse(resURL); - - // Is it on a network drive? - if (u.protocol === 'file:' && u.host) { - isNetworkDrive = true; - } + const fileURL = this.extractFileURL(e.message); + if (this.isNetworkDrive(fileURL)) { + // Network drive: Should be allowed. + if (!shell.openExternal(decodeURI(fileURL))) { + console.log(`[${this.props.name}] shell.openExternal failed: ${fileURL}`); } - } - - // Network drive: Should be allowed. - if (isNetworkDrive) { - if (!shell.openExternal(decodeURI(resURL))) { - console.log(`[${this.props.name}] shell.openExternal failed: ${resURL}`); - } - } - // Local drive such as 'C:\Windows': Should not be allowed. - else { + } else { + // Local drive such as 'C:\Windows': Should not be allowed. console.error(message); } break; @@ -256,6 +239,22 @@ const MattermostView = createReactClass({ ); }, + extractFileURL(message) { + const matched = message.match(/Not allowed to load local resource:\s*(.+)/); + if (matched) { + return matched[1]; + } + return ''; + }, + + isNetworkDrive(fileURL) { + const u = url.parse(fileURL); + if (u.protocol === 'file:' && u.host) { + return true; + } + return false; + }, + render() { const errorView = this.state.errorInfo ? ( Date: Sun, 25 Feb 2018 10:51:45 +0900 Subject: [PATCH 3/3] Fixed an issue where clicking on a file:// protocol path does not open windows explorer since version 3.5.0. --- src/browser/components/MattermostView.jsx | 42 +++++++++++++---------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/src/browser/components/MattermostView.jsx b/src/browser/components/MattermostView.jsx index 768b4964..968895ee 100644 --- a/src/browser/components/MattermostView.jsx +++ b/src/browser/components/MattermostView.jsx @@ -15,6 +15,25 @@ const ErrorView = require('./ErrorView.jsx'); const preloadJS = `file://${remote.app.getAppPath()}/browser/webview/mattermost_bundle.js`; +function extractFileURL(message) { + const matched = message.match(/Not allowed to load local resource:\s*(.+)/); + if (matched) { + return matched[1]; + } + return ''; +} + +function isNetworkDrive(fileURL) { + const u = url.parse(fileURL); + if (u.protocol === 'file:' && u.host) { + // Disallow localhost, 127.0.0.1, ::1. + if (!u.host.match(/^localhost$|^127\.0\.0\.1$|^\[::1\]$/)) { + return true; + } + } + return false; +} + const MattermostView = createReactClass({ propTypes: { name: PropTypes.string, @@ -156,9 +175,9 @@ const MattermostView = createReactClass({ case 1: console.warn(message); break; - case 2: - const fileURL = this.extractFileURL(e.message); - if (this.isNetworkDrive(fileURL)) { + case 2: { + const fileURL = extractFileURL(e.message); + if (isNetworkDrive(fileURL)) { // Network drive: Should be allowed. if (!shell.openExternal(decodeURI(fileURL))) { console.log(`[${this.props.name}] shell.openExternal failed: ${fileURL}`); @@ -168,6 +187,7 @@ const MattermostView = createReactClass({ console.error(message); } break; + } default: console.log(message); break; @@ -239,22 +259,6 @@ const MattermostView = createReactClass({ ); }, - extractFileURL(message) { - const matched = message.match(/Not allowed to load local resource:\s*(.+)/); - if (matched) { - return matched[1]; - } - return ''; - }, - - isNetworkDrive(fileURL) { - const u = url.parse(fileURL); - if (u.protocol === 'file:' && u.host) { - return true; - } - return false; - }, - render() { const errorView = this.state.errorInfo ? (