Skip to content
This repository was archived by the owner on Dec 11, 2019. It is now read-only.

Commit e2037f6

Browse files
committed
Fix mailto handling when Brave is default
Auditors: @diracdeltas Fix #4487
1 parent d514e55 commit e2037f6

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

app/cmdLine.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,25 @@ const focusOrOpenWindow = function (url) {
4343
return true
4444
}
4545

46+
const isProtocolHandled = (protocol) => {
47+
protocol = (protocol || '').split(':')[0]
48+
return navigatableTypes.includes(protocol) ||
49+
electron.session.defaultSession.protocol.isNavigatorProtocolHandled(protocol)
50+
}
51+
4652
// Checks an array of arguments if it can find a url
4753
const getUrlFromCommandLine = (argv) => {
4854
if (argv) {
4955
if (argv.length === 2 && !argv[1].startsWith('-')) {
5056
const parsedUrl = urlParse(argv[1])
51-
if (navigatableTypes.includes(parsedUrl.protocol)) {
57+
if (isProtocolHandled(parsedUrl.protocol)) {
5258
return argv[1]
5359
}
5460
}
5561
const index = argv.indexOf('--')
5662
if (index !== -1 && index + 1 < argv.length && !argv[index + 1].startsWith('-')) {
5763
const parsedUrl = urlParse(argv[index + 1])
58-
if (navigatableTypes.includes(parsedUrl.protocol)) {
64+
if (isProtocolHandled(parsedUrl.protocol)) {
5965
return argv[index + 1]
6066
}
6167
}
@@ -68,7 +74,7 @@ if (!isDarwin) {
6874
const openUrl = getUrlFromCommandLine(process.argv)
6975
if (openUrl) {
7076
const parsedUrl = urlParse(openUrl)
71-
if (navigatableTypes.includes(parsedUrl.protocol)) {
77+
if (isProtocolHandled(parsedUrl.protocol)) {
7278
module.exports.newWindowURL = openUrl
7379
}
7480
}
@@ -101,7 +107,7 @@ app.on('will-finish-launching', () => {
101107
app.on('open-url', (event, path) => {
102108
event.preventDefault()
103109
const parsedUrl = urlParse(path)
104-
if (navigatableTypes.includes(parsedUrl.protocol)) {
110+
if (isProtocolHandled(parsedUrl.protocol)) {
105111
if (!focusOrOpenWindow(path)) {
106112
module.exports.newWindowURL = path
107113
}

js/lib/urlutil.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ const UrlUtil = {
108108
// for cases, pure string
109109
const case3Reg = /[\?\.\/\s:]/
110110
// for cases, data:uri, view-source:uri and about
111-
const case4Reg = /^data|view-source|about|chrome-extension:.*/
111+
const case4Reg = /^data|view-source|mailto|about|chrome-extension:.*/
112112

113113
let str = input.trim()
114114
let scheme = this.getScheme(str)

test/unit/lib/urlutilTest.js

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ describe('urlutil', function () {
7575
it('returns false when input is chrome-extension', function () {
7676
assert.equal(UrlUtil.isNotURL('chrome-extension://fmfcbgogabcbclcofgocippekhfcmgfj/cast_sender.js'), false)
7777
})
78+
it('returns false when input is mailto', function () {
79+
assert.equal(UrlUtil.isNotURL('mailto:brian@brave.com'), false)
80+
})
7881
describe('search query', function () {
7982
it('returns true when input starts with ?', function () {
8083
assert.equal(UrlUtil.isNotURL('?brave'), true)

0 commit comments

Comments
 (0)