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

Commit

Permalink
Merge pull request #9501 from brave/fix/urlparse
Browse files Browse the repository at this point in the history
Fix url parsing bug
  • Loading branch information
bsclifton committed Jun 15, 2017
1 parent 02a7878 commit 3a454ec
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 27 deletions.
8 changes: 0 additions & 8 deletions app/common/lib/siteSuggestions.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,6 @@ const tokenizeInput = (data) => {
parts = parts.concat(parsedUrl.pathname.split(/[.\s\\/]/))
}
if (parsedUrl.query) {
// I think fast-url-parser has a bug in it where it returns an object for query
// instead of a string. Object is supported but only when you pass in true
// for the second value of parse which we don't do.
// We can remove this when we change away from using fast-url-parser in favour of the
// Chrome URL parser.
if (parsedUrl.query.constructor !== String) {
parsedUrl.query = Object.entries(parsedUrl.query).map((x) => x.join('=')).join('&')
}
parts = parts.concat(parsedUrl.query.split(/[&=]/))
}
if (parsedUrl.protocol) {
Expand Down
20 changes: 2 additions & 18 deletions app/common/urlParse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */

const LRUCache = require('lru-cache')
const urlParse = require('fast-url-parser').parse
const urlParse = require('url').parse
const config = require('../../js/constants/config')
let cachedUrlParse = new LRUCache(config.cache.urlParse)

Expand All @@ -14,23 +14,7 @@ module.exports = (url, ...args) => {
return Object.assign({}, parsedUrl)
}

// In fast-url-parser href, port, prependSlash, protocol, and query
// are lazy so access them.
const raw = urlParse(url, ...args)
parsedUrl = {
auth: raw.auth,
hash: raw.hash,
host: raw.host,
hostname: raw.hostname,
href: raw.href,
path: raw.path,
pathname: raw.pathname,
port: raw.port,
protocol: raw.protocol,
query: raw.query,
search: raw.search,
slashes: raw.slashes
}
parsedUrl = urlParse(url, ...args)
cachedUrlParse.set(url, parsedUrl)
return parsedUrl
}
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
"clipboard-copy": "^1.0.0",
"electron-localshortcut": "^0.6.0",
"electron-squirrel-startup": "brave/electron-squirrel-startup",
"fast-url-parser": "^1.1.3",
"file-loader": "^0.8.5",
"font-awesome": "^4.5.0",
"font-awesome-webpack": "0.0.4",
Expand Down

0 comments on commit 3a454ec

Please sign in to comment.