Repository: sindresorhus/got (ts)

Issue:
URI malformed when trying to get URL with URL-encoded chars
Hello,

Catched URI malformed error in new "got", when I trying to send request to URL with URL-encoded chars.
URL examples:
https://www.kinopoisk.ru/community/city/%D2%E0%EB%EB%E8%ED/
https://www.kinopoisk.ru/news/keyword/%C7%E2%E5%E7%E4%ED%FB%E5+%E2%EE%E9%ED%FB/

nodejs: 9.2.0
got: 8.0.0

Failed code:
```js
const got = require('got');

(async () => {
	try {
		const response = await got('https://www.kinopoisk.ru/community/city/%D2%E0%EB%EB%E8%ED/');
		console.log(response);
	} catch (error) {
		console.log(error);
	}
})();
```
```
URIError: URI malformed
    at decodeURI (<anonymous>)
    at module.exports (/Users/kirill-m/git/test/node_modules/normalize-url/index.js:87:21)
    at /Users/kirill-m/git/test/node_modules/cacheable-request/src/index.js:43:16
    at get (/Users/kirill-m/git/test/node_modules/got/index.js:98:20)
    at Promise.resolve.then.size (/Users/kirill-m/git/test/node_modules/got/index.js:274:5)
    at <anonymous>
```

Broken at this commit: https://github.com/sindresorhus/got/commit/3c7920507fae88a5f53d0640b5116fa34a5ed829

Any ideas?

Pull request:
Validate that `url` is UTF-8 encoded
Opted to decode without assignment back to `url` so that requests and other error messages continue to display the user provided `url` value. 

---
Closes #420 

Patch:
diff --git a/index.js b/index.js
index e515eae..89aa283 100644
--- a/index.js
+++ b/index.js
@@ -444,6 +444,13 @@ function normalizeArguments(url, opts) {
 		throw new TypeError(`Parameter \`url\` must be a string or object, not ${is(url)}`);
 	} else if (is.string(url)) {
 		url = url.replace(/^unix:/, 'http://$&');
+
+		try {
+			decodeURI(url);
+		} catch (err) {
+			throw new Error('Parameter `url` must contain valid UTF-8 character sequences');
+		}
+
 		url = urlParseLax(url);
 		if (url.auth) {
 			throw new Error('Basic authentication must be done with the `auth` option');


Test patch:
diff --git a/test/arguments.js b/test/arguments.js
index 1038ac3..6546888 100644
--- a/test/arguments.js
+++ b/test/arguments.js
@@ -29,6 +29,11 @@ test('url is required', async t => {
 	t.regex(err.message, /Parameter `url` must be a string or object, not undefined/);
 });
 
+test('url should be utf-8 encoded', async t => {
+	const err = await t.throws(got(`${s.url}/%D2%E0%EB%EB%E8%ED`));
+	t.regex(err.message, /Parameter `url` must contain valid UTF-8 character sequences/);
+});
+
 test('options are optional', async t => {
 	t.is((await got(`${s.url}/test`)).body, '/test');
 });