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

Commit

Permalink
Fix mailto handling when Brave is default
Browse files Browse the repository at this point in the history
Auditors: @diracdeltas

Fix #4487
  • Loading branch information
bbondy committed Oct 4, 2016
1 parent d514e55 commit e2037f6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
14 changes: 10 additions & 4 deletions app/cmdLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,25 @@ const focusOrOpenWindow = function (url) {
return true
}

const isProtocolHandled = (protocol) => {
protocol = (protocol || '').split(':')[0]
return navigatableTypes.includes(protocol) ||
electron.session.defaultSession.protocol.isNavigatorProtocolHandled(protocol)
}

// Checks an array of arguments if it can find a url
const getUrlFromCommandLine = (argv) => {
if (argv) {
if (argv.length === 2 && !argv[1].startsWith('-')) {
const parsedUrl = urlParse(argv[1])
if (navigatableTypes.includes(parsedUrl.protocol)) {
if (isProtocolHandled(parsedUrl.protocol)) {
return argv[1]
}
}
const index = argv.indexOf('--')
if (index !== -1 && index + 1 < argv.length && !argv[index + 1].startsWith('-')) {
const parsedUrl = urlParse(argv[index + 1])
if (navigatableTypes.includes(parsedUrl.protocol)) {
if (isProtocolHandled(parsedUrl.protocol)) {
return argv[index + 1]
}
}
Expand All @@ -68,7 +74,7 @@ if (!isDarwin) {
const openUrl = getUrlFromCommandLine(process.argv)
if (openUrl) {
const parsedUrl = urlParse(openUrl)
if (navigatableTypes.includes(parsedUrl.protocol)) {
if (isProtocolHandled(parsedUrl.protocol)) {
module.exports.newWindowURL = openUrl
}
}
Expand Down Expand Up @@ -101,7 +107,7 @@ app.on('will-finish-launching', () => {
app.on('open-url', (event, path) => {
event.preventDefault()
const parsedUrl = urlParse(path)
if (navigatableTypes.includes(parsedUrl.protocol)) {
if (isProtocolHandled(parsedUrl.protocol)) {
if (!focusOrOpenWindow(path)) {
module.exports.newWindowURL = path
}
Expand Down
2 changes: 1 addition & 1 deletion js/lib/urlutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const UrlUtil = {
// for cases, pure string
const case3Reg = /[\?\.\/\s:]/
// for cases, data:uri, view-source:uri and about
const case4Reg = /^data|view-source|about|chrome-extension:.*/
const case4Reg = /^data|view-source|mailto|about|chrome-extension:.*/

let str = input.trim()
let scheme = this.getScheme(str)
Expand Down
3 changes: 3 additions & 0 deletions test/unit/lib/urlutilTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ describe('urlutil', function () {
it('returns false when input is chrome-extension', function () {
assert.equal(UrlUtil.isNotURL('chrome-extension://fmfcbgogabcbclcofgocippekhfcmgfj/cast_sender.js'), false)
})
it('returns false when input is mailto', function () {
assert.equal(UrlUtil.isNotURL('mailto:brian@brave.com'), false)
})
describe('search query', function () {
it('returns true when input starts with ?', function () {
assert.equal(UrlUtil.isNotURL('?brave'), true)
Expand Down

1 comment on commit e2037f6

@diracdeltas
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

Please # to comment.