-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly encode url with unicode characters (#1291)
* fix: properly encode url with unicode characters * release: 2.6.3
- Loading branch information
Showing
6 changed files
with
79 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
|
||
import Url from 'url'; | ||
import Stream from 'stream'; | ||
import {URL} from 'whatwg-url'; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
LinusU
Author
Member
|
||
import Headers, { exportNodeCompatibleHeaders } from './headers.js'; | ||
import Body, { clone, extractContentType, getTotalBytes } from './body'; | ||
|
||
|
@@ -18,6 +19,39 @@ const INTERNALS = Symbol('Request internals'); | |
const parse_url = Url.parse; | ||
const format_url = Url.format; | ||
|
||
/** | ||
* Wrapper around `new URL` to handle arbitrary URLs | ||
* | ||
* @param {string} urlStr | ||
* @return {void} | ||
*/ | ||
function parseURL(urlStr) { | ||
/* | ||
Check whether the URL is absolute or not | ||
Scheme: https://tools.ietf.org/html/rfc3986#section-3.1 | ||
Absolute URL: https://tools.ietf.org/html/rfc3986#section-4.3 | ||
*/ | ||
if (/^[a-zA-Z][a-zA-Z\d+\-.]*:/.exec(urlStr)) { | ||
const url = new URL(urlStr); | ||
|
||
return { | ||
path: url.pathname, | ||
pathname: url.pathname, | ||
hostname: url.hostname, | ||
protocol: url.protocol, | ||
port: url.port, | ||
hash: url.hash, | ||
search: url.search, | ||
query: url.query, | ||
This comment has been minimized.
Sorry, something went wrong.
jimmywarting
Collaborator
|
||
href: url.href, | ||
} | ||
} | ||
|
||
// Fallback to old implementation for arbitrary URLs | ||
return parse_url(urlStr); | ||
} | ||
|
||
const streamDestructionSupported = 'destroy' in Stream.Readable.prototype; | ||
|
||
/** | ||
|
@@ -59,14 +93,14 @@ export default class Request { | |
// in order to support Node.js' Url objects; though WHATWG's URL objects | ||
// will fall into this branch also (since their `toString()` will return | ||
// `href` property anyway) | ||
parsedURL = parse_url(input.href); | ||
parsedURL = parseURL(input.href); | ||
} else { | ||
// coerce input to a string before attempting to parse | ||
parsedURL = parse_url(`${input}`); | ||
parsedURL = parseURL(`${input}`); | ||
} | ||
input = {}; | ||
} else { | ||
parsedURL = parse_url(input.url); | ||
parsedURL = parseURL(input.url); | ||
} | ||
|
||
let method = init.method || input.method || 'GET'; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This import on line 12 is causing errors in other projects.