Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
W
web-monitor
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
web-monitor
Commits
8865514c
Commit
8865514c
authored
Jun 15, 2020
by
花裤衩
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix[utils]: param2Obj bug when url params includes ==
parent
e2fd7c75
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
21 deletions
+46
-21
utils.js
mock/utils.js
+13
-11
index.js
src/utils/index.js
+12
-10
param2Obj.spec.js
tests/unit/utils/param2Obj.spec.js
+21
-0
No files found.
mock/utils.js
View file @
8865514c
...
...
@@ -2,20 +2,22 @@
* @param {string} url
* @returns {Object}
*/
function
param2Obj
(
url
)
{
const
search
=
url
.
split
(
'?'
)[
1
]
export
function
param2Obj
(
url
)
{
const
search
=
decodeURIComponent
(
url
.
split
(
'?'
)[
1
]).
replace
(
/
\+
/g
,
' '
)
if
(
!
search
)
{
return
{}
}
return
JSON
.
parse
(
'{"'
+
decodeURIComponent
(
search
)
.
replace
(
/"/g
,
'
\\
"'
)
.
replace
(
/&/g
,
'","'
)
.
replace
(
/=/g
,
'":"'
)
.
replace
(
/
\+
/g
,
' '
)
+
'"}'
)
const
obj
=
{}
const
searchArr
=
search
.
split
(
'&'
)
searchArr
.
forEach
(
v
=>
{
const
index
=
v
.
indexOf
(
'='
)
if
(
index
!==
-
1
)
{
const
name
=
v
.
substring
(
0
,
index
)
const
val
=
v
.
substring
(
index
+
1
,
v
.
length
)
obj
[
name
]
=
val
}
})
return
obj
}
module
.
exports
=
{
...
...
src/utils/index.js
View file @
8865514c
...
...
@@ -99,17 +99,19 @@ export function formatTime(time, option) {
* @returns {Object}
*/
export
function
param2Obj
(
url
)
{
const
search
=
url
.
split
(
'?'
)[
1
]
const
search
=
decodeURIComponent
(
url
.
split
(
'?'
)[
1
]).
replace
(
/
\+
/g
,
' '
)
if
(
!
search
)
{
return
{}
}
return
JSON
.
parse
(
'{"'
+
decodeURIComponent
(
search
)
.
replace
(
/"/g
,
'
\\
"'
)
.
replace
(
/&/g
,
'","'
)
.
replace
(
/=/g
,
'":"'
)
.
replace
(
/
\+
/g
,
' '
)
+
'"}'
)
const
obj
=
{}
const
searchArr
=
search
.
split
(
'&'
)
searchArr
.
forEach
(
v
=>
{
const
index
=
v
.
indexOf
(
'='
)
if
(
index
!==
-
1
)
{
const
name
=
v
.
substring
(
0
,
index
)
const
val
=
v
.
substring
(
index
+
1
,
v
.
length
)
obj
[
name
]
=
val
}
})
return
obj
}
tests/unit/utils/param2Obj.spec.js
0 → 100644
View file @
8865514c
/**
* @param {string} url
* @returns {Object}
*/
export
function
param2Obj
(
url
)
{
const
search
=
decodeURIComponent
(
url
.
split
(
'?'
)[
1
]).
replace
(
/
\+
/g
,
' '
)
if
(
!
search
)
{
return
{}
}
const
obj
=
{}
const
searchArr
=
search
.
split
(
'&'
)
searchArr
.
forEach
(
v
=>
{
const
index
=
v
.
indexOf
(
'='
)
if
(
index
!==
-
1
)
{
const
name
=
v
.
substring
(
0
,
index
)
const
val
=
v
.
substring
(
index
+
1
,
v
.
length
)
obj
[
name
]
=
val
}
})
return
obj
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment