Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
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
Alex
next.js
Commits
5aed1d2e
Unverified
Commit
5aed1d2e
authored
Sep 10, 2020
by
Jan Potoms
Committed by
GitHub
Sep 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Correct query behavior for falsey values to pre 9.5.1 behavior (#16608)
Fixes
https://github.com/vercel/next.js/issues/16147
parent
ca986abd
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
85 additions
and
4 deletions
+85
-4
querystring.ts
packages/next/next-server/lib/router/utils/querystring.ts
+14
-2
index.test.js
test/integration/build-output/test/index.test.js
+1
-1
query-params.js
test/integration/client-navigation/pages/nav/query-params.js
+43
-0
query.js
test/integration/client-navigation/pages/query.js
+6
-0
index.test.js
test/integration/client-navigation/test/index.test.js
+20
-0
index.test.js
test/integration/size-limit/test/index.test.js
+1
-1
No files found.
packages/next/next-server/lib/router/utils/querystring.ts
View file @
5aed1d2e
...
@@ -16,15 +16,27 @@ export function searchParamsToUrlQuery(
...
@@ -16,15 +16,27 @@ export function searchParamsToUrlQuery(
return
query
return
query
}
}
function
stringifyUrlQueryParam
(
param
:
string
):
string
{
if
(
typeof
param
===
'string'
||
(
typeof
param
===
'number'
&&
!
isNaN
(
param
))
||
typeof
param
===
'boolean'
)
{
return
String
(
param
)
}
else
{
return
''
}
}
export
function
urlQueryToSearchParams
(
export
function
urlQueryToSearchParams
(
urlQuery
:
ParsedUrlQuery
urlQuery
:
ParsedUrlQuery
):
URLSearchParams
{
):
URLSearchParams
{
const
result
=
new
URLSearchParams
()
const
result
=
new
URLSearchParams
()
Object
.
entries
(
urlQuery
).
forEach
(([
key
,
value
])
=>
{
Object
.
entries
(
urlQuery
).
forEach
(([
key
,
value
])
=>
{
if
(
Array
.
isArray
(
value
))
{
if
(
Array
.
isArray
(
value
))
{
value
.
forEach
((
item
)
=>
result
.
append
(
key
,
item
))
value
.
forEach
((
item
)
=>
result
.
append
(
key
,
stringifyUrlQueryParam
(
item
)
))
}
else
{
}
else
{
result
.
set
(
key
,
value
)
result
.
set
(
key
,
stringifyUrlQueryParam
(
value
)
)
}
}
})
})
return
result
return
result
...
...
test/integration/build-output/test/index.test.js
View file @
5aed1d2e
...
@@ -104,7 +104,7 @@ describe('Build Output', () => {
...
@@ -104,7 +104,7 @@ describe('Build Output', () => {
expect
(
parseFloat
(
err404FirstLoad
)
-
63.6
).
toBeLessThanOrEqual
(
0
)
expect
(
parseFloat
(
err404FirstLoad
)
-
63.6
).
toBeLessThanOrEqual
(
0
)
expect
(
err404FirstLoad
.
endsWith
(
'kB'
)).
toBe
(
true
)
expect
(
err404FirstLoad
.
endsWith
(
'kB'
)).
toBe
(
true
)
expect
(
parseFloat
(
sharedByAll
)
-
60.
1
).
toBeLessThanOrEqual
(
0
)
expect
(
parseFloat
(
sharedByAll
)
-
60.
2
).
toBeLessThanOrEqual
(
0
)
expect
(
sharedByAll
.
endsWith
(
'kB'
)).
toBe
(
true
)
expect
(
sharedByAll
.
endsWith
(
'kB'
)).
toBe
(
true
)
if
(
_appSize
.
endsWith
(
'kB'
))
{
if
(
_appSize
.
endsWith
(
'kB'
))
{
...
...
test/integration/client-navigation/pages/nav/query-params.js
0 → 100644
View file @
5aed1d2e
import
{
useRouter
}
from
'next/router'
export
default
function
Page
()
{
const
router
=
useRouter
()
return
(
<>
<
button
id
=
"click-me"
onClick
=
{()
=>
router
.
push
({
pathname
:
'/query'
,
query
:
{
param1
:
''
,
param2
:
undefined
,
param3
:
null
,
param4
:
0
,
param5
:
false
,
param6
:
[],
param7
:
{},
param8
:
NaN
,
param9
:
new
Date
(
1234
),
param10
:
/hello/
,
param11
:
[
''
,
undefined
,
null
,
0
,
false
,
[],
{},
NaN
,
new
Date
(
1234
),
/hello/
,
],
},
})
}
>
Click
me
<
/button
>
<
/
>
)
}
test/integration/client-navigation/pages/query.js
0 → 100644
View file @
5aed1d2e
import
{
useRouter
}
from
'next/router'
export
default
function
Page
()
{
const
router
=
useRouter
()
return
<
pre
id
=
"query-value"
>
{
JSON
.
stringify
(
router
.
query
,
null
,
2
)}
<
/pre
>
}
test/integration/client-navigation/test/index.test.js
View file @
5aed1d2e
...
@@ -801,6 +801,26 @@ describe('Client Navigation', () => {
...
@@ -801,6 +801,26 @@ describe('Client Navigation', () => {
await
browser
.
close
()
await
browser
.
close
()
})
})
it
(
'should handle undefined in router.push'
,
async
()
=>
{
const
browser
=
await
webdriver
(
context
.
appPort
,
'/nav/query-params'
)
await
browser
.
elementByCss
(
'#click-me'
).
click
()
const
query
=
JSON
.
parse
(
await
browser
.
waitForElementByCss
(
'#query-value'
).
text
()
)
expect
(
query
).
toEqual
({
param1
:
''
,
param2
:
''
,
param3
:
''
,
param4
:
'0'
,
param5
:
'false'
,
param7
:
''
,
param8
:
''
,
param9
:
''
,
param10
:
''
,
param11
:
[
''
,
''
,
''
,
'0'
,
'false'
,
''
,
''
,
''
,
''
,
''
],
})
})
})
})
describe
(
'with querystring relative urls'
,
()
=>
{
describe
(
'with querystring relative urls'
,
()
=>
{
...
...
test/integration/size-limit/test/index.test.js
View file @
5aed1d2e
...
@@ -100,7 +100,7 @@ describe('Production response size', () => {
...
@@ -100,7 +100,7 @@ describe('Production response size', () => {
)
)
// These numbers are without gzip compression!
// These numbers are without gzip compression!
const
delta
=
responseSizesBytes
-
1
69
*
1024
const
delta
=
responseSizesBytes
-
1
70
*
1024
expect
(
delta
).
toBeLessThanOrEqual
(
1024
)
// don't increase size more than 1kb
expect
(
delta
).
toBeLessThanOrEqual
(
1024
)
// don't increase size more than 1kb
expect
(
delta
).
toBeGreaterThanOrEqual
(
-
1024
)
// don't decrease size more than 1kb without updating target
expect
(
delta
).
toBeGreaterThanOrEqual
(
-
1024
)
// don't decrease size more than 1kb without updating target
})
})
...
...
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