-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
1 changed file
with
26 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,36 @@ | ||
import getRealRoute from '../get-real-route' | ||
|
||
function encodeQueryString (url) { | ||
if (typeof url === 'string') { | ||
const urls = url.split('?') | ||
if (typeof url !== 'string') { | ||
return url | ||
} | ||
const index = url.indexOf('?') | ||
|
||
url = urls[0] | ||
if (index === -1) { | ||
return url | ||
} | ||
|
||
const params = []; | ||
(urls[1] || '').split('&').forEach(function (pair) { | ||
if (pair) { | ||
const pairs = pair.split('=') | ||
params.push(pairs[0] + '=' + encodeURIComponent(pairs[1])) | ||
} | ||
}) | ||
const query = url.substr(index + 1).trim().replace(/^(\?|#|&)/, '') | ||
|
||
return params.length ? url + '?' + params.join('&') : url | ||
if (!query) { | ||
return url | ||
} | ||
return url | ||
|
||
url = url.substr(0, index) | ||
|
||
const params = [] | ||
|
||
query.split('&').forEach(param => { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
fxy060608
Author
Collaborator
|
||
const parts = param.replace(/\+/g, ' ').split('=') | ||
const key = parts.shift() | ||
const val = parts.length > 0 | ||
? parts.join('=') | ||
: '' | ||
|
||
params.push(key + '=' + encodeURIComponent(val)) | ||
}) | ||
|
||
return params.length ? url + '?' + params.join('&') : url | ||
} | ||
|
||
function createValidator (type) { | ||
|
这里node 原生不是有 querystring 吗
完全没必要自己写吧???