Skip to content

Commit

Permalink
url file space issue fixed along with a test
Browse files Browse the repository at this point in the history
  • Loading branch information
buttersnipps committed Apr 14, 2018
1 parent 68ecb38 commit 00f4a3f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 7 additions & 2 deletions js/lib/urlutil.js
Expand Up @@ -51,6 +51,8 @@ const UrlUtil = {
* @returns {String} path with a scheme
*/
prependScheme: function (input) {


if (input === undefined || input === null) {
return input
}
Expand All @@ -63,12 +65,13 @@ const UrlUtil = {
// detect absolute file paths
if (input.startsWith('/')) {
input = fileScheme + input

}

// If there's no scheme, prepend the default scheme
if (!UrlUtil.hasScheme(input)) {
input = defaultScheme + input
}


return input
},
Expand Down Expand Up @@ -114,8 +117,10 @@ const UrlUtil = {
const case3Reg = /[?./\s:]/
// for cases, data:uri, view-source:uri and about
const case4Reg = /^(data|view-source|mailto|about|chrome-extension|chrome-devtools|magnet|chrome):.*/

let urlifyStr = input.replace(' ','%20')
let str = urlifyStr.trim()

let str = input.trim()
const scheme = UrlUtil.getScheme(str)

if (str.toLowerCase() === 'localhost') {
Expand Down
5 changes: 4 additions & 1 deletion test/unit/lib/urlutilTest.js
Expand Up @@ -77,7 +77,7 @@ describe('urlutil', function () {
})
it('contains a hostname and port number', function () {
assert.equal(urlUtil.isNotURL('someBraveServer:8089'), false)
})
})
it('starts or ends with whitespace', function () {
assert.equal(urlUtil.isNotURL(' http://brave.com '), false)
assert.equal(urlUtil.isNotURL('\n\nhttp://brave.com\n\n'), false)
Expand Down Expand Up @@ -151,6 +151,9 @@ describe('urlutil', function () {
it('has space in schema', function () {
assert.equal(urlUtil.isNotURL('https ://brave.com'), true)
})
it('is a string with whitespace but needs to be URL space encoded',function(){
assert.equal(urlUtil.isNotURL('dog%20cat'),true)
})
})
})

Expand Down

0 comments on commit 00f4a3f

Please sign in to comment.