Skip to content

Commit

Permalink
Add additional isUrl check, closes #1462
Browse files Browse the repository at this point in the history
  • Loading branch information
rickycodes committed Oct 6, 2020
1 parent 15aae28 commit 22c52b5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions app/util/browser.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import URL from 'url-parse';
import isUrl from 'is-url';

/**
* Returns a sanitized url, which could be a search engine url if
Expand All @@ -11,8 +12,8 @@ import URL from 'url-parse';
*/
export default function onUrlSubmit(input, searchEngine = 'Google', defaultProtocol = 'https://') {
//Check if it's a url or a keyword
const res = input.match(/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!&',;=.+]+$/g);
if (res === null) {
const regEx = new RegExp(/^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w.-]+)+[\w\-._~:/?#[\]@!&',;=.+]+$/g);
if (!isUrl(input) && !regEx.test(input)) {
// Add exception for localhost
if (!input.startsWith('http://localhost') && !input.startsWith('localhost')) {
// In case of keywords we default to google search
Expand All @@ -23,7 +24,7 @@ export default function onUrlSubmit(input, searchEngine = 'Google', defaultProto
return searchUrl;
}
}
const hasProtocol = input.match(/^[a-z]*:\/\//);
const hasProtocol = /^[a-z]*:\/\//.test(input);
const sanitizedURL = hasProtocol ? input : `${defaultProtocol}${input}`;
return sanitizedURL;
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"events": "3.0.0",
"fuse.js": "3.4.4",
"https-browserify": "0.0.1",
"is-url": "^1.2.4",
"json-rpc-engine": "5.1.5",
"json-rpc-middleware-stream": "2.1.1",
"lottie-react-native": "git+https://github.com/MetaMask/lottie-react-native.git#7ce6a78ac4ac7b9891bc513cb3f12f8b9c9d9106",
Expand All @@ -128,7 +129,7 @@
"react-native": "0.62.2",
"react-native-actionsheet": "beefe/react-native-actionsheet#107/head",
"react-native-aes-crypto": "^1.3.9",
"react-native-aes-crypto-forked": "git+https://github.com/MetaMask/react-native-aes-crypto-forked.git#397d5db5250e8e7408294807965b5b9fd4ca6a25",
"react-native-aes-crypto-forked": "git+https://github.com/MetaMask/react-native-aes-crypto-forked.git#397d5db5250e8e7408294807965b5b9fd4ca6a25",
"react-native-animated-fox": "git+https://github.com/MetaMask/react-native-animated-fox.git#16e38d54d829709e497f196e31fa8ff00cdf2aa9",
"react-native-background-timer": "2.1.1",
"react-native-branch": "5.0.0-beta.1",
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6961,6 +6961,11 @@ [email protected], is-typedarray@^1.0.0, is-typedarray@~1.0.0:
resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a"
integrity sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=

is-url@^1.2.4:
version "1.2.4"
resolved "https://registry.yarnpkg.com/is-url/-/is-url-1.2.4.tgz#04a4df46d28c4cff3d73d01ff06abeb318a1aa52"
integrity sha512-ITvGim8FhRiYe4IQ5uHSkj7pVaPDrCTkNd3yq3cV7iZAcJdHTUMPMEHcqSOy9xZ9qFenQCvi+2wjH9a1nXqHww==

is-weakmap@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/is-weakmap/-/is-weakmap-2.0.1.tgz#5008b59bdc43b698201d18f62b37b2ca243e8cf2"
Expand Down

0 comments on commit 22c52b5

Please sign in to comment.