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
4442fe2f
Unverified
Commit
4442fe2f
authored
Oct 22, 2020
by
JJ Kasper
Committed by
GitHub
Oct 22, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update redirect query encoding (#18149)
* Update redirect query encoding * Add additional tests
parent
ac8a0c48
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
11 deletions
+56
-11
next-server.ts
packages/next/next-server/server/next-server.ts
+2
-9
index.test.js
test/integration/custom-routes/test/index.test.js
+31
-0
security.js
test/integration/production/test/security.js
+23
-2
No files found.
packages/next/next-server/server/next-server.ts
View file @
4442fe2f
...
@@ -730,9 +730,7 @@ export default class Server {
...
@@ -730,9 +730,7 @@ export default class Server {
const
{
query
}
=
parsedDestination
const
{
query
}
=
parsedDestination
delete
(
parsedDestination
as
any
).
query
delete
(
parsedDestination
as
any
).
query
parsedDestination
.
search
=
stringifyQs
(
query
,
undefined
,
undefined
,
{
parsedDestination
.
search
=
stringifyQs
(
query
)
encodeURIComponent
:
(
str
:
string
)
=>
str
,
}
as
any
)
const
updatedDestination
=
formatUrl
(
parsedDestination
)
const
updatedDestination
=
formatUrl
(
parsedDestination
)
...
@@ -774,12 +772,7 @@ export default class Server {
...
@@ -774,12 +772,7 @@ export default class Server {
if
(
parsedDestination
.
protocol
)
{
if
(
parsedDestination
.
protocol
)
{
const
{
query
}
=
parsedDestination
const
{
query
}
=
parsedDestination
delete
(
parsedDestination
as
any
).
query
delete
(
parsedDestination
as
any
).
query
parsedDestination
.
search
=
stringifyQs
(
parsedDestination
.
search
=
stringifyQs
(
query
)
query
,
undefined
,
undefined
,
{
encodeURIComponent
:
(
str
)
=>
str
}
)
const
target
=
formatUrl
(
parsedDestination
)
const
target
=
formatUrl
(
parsedDestination
)
const
proxy
=
new
Proxy
({
const
proxy
=
new
Proxy
({
...
...
test/integration/custom-routes/test/index.test.js
View file @
4442fe2f
...
@@ -210,6 +210,18 @@ const runTests = (isDev = false) => {
...
@@ -210,6 +210,18 @@ const runTests = (isDev = false) => {
})
})
})
})
it
(
'should have correct encoding for params with catchall rewrite'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/catchall-rewrite/hello%20world%3Fw%3D24%26focalpoint%3Dcenter?a=b'
)
const
$
=
cheerio
.
load
(
html
)
expect
(
JSON
.
parse
(
$
(
'#__NEXT_DATA__'
).
html
()).
query
).
toEqual
({
a
:
'b'
,
path
:
[
'hello%20world%3Fw%3D24%26focalpoint%3Dcenter'
],
})
})
it
(
'should have correct query for catchall rewrite'
,
async
()
=>
{
it
(
'should have correct query for catchall rewrite'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/catchall-query/hello/world?a=b'
)
const
html
=
await
renderViaHTTP
(
appPort
,
'/catchall-query/hello/world?a=b'
)
const
$
=
cheerio
.
load
(
html
)
const
$
=
cheerio
.
load
(
html
)
...
@@ -245,6 +257,25 @@ const runTests = (isDev = false) => {
...
@@ -245,6 +257,25 @@ const runTests = (isDev = false) => {
})
})
})
})
it
(
'should have correctly encoded params in query for redirect'
,
async
()
=>
{
const
res
=
await
fetchViaHTTP
(
appPort
,
'/query-redirect/hello%20world%3Fw%3D24%26focalpoint%3Dcenter/world?a=b'
,
undefined
,
{
redirect
:
'manual'
,
}
)
const
{
pathname
,
query
}
=
url
.
parse
(
res
.
headers
.
get
(
'location'
),
true
)
expect
(
res
.
status
).
toBe
(
307
)
expect
(
pathname
).
toBe
(
'/with-params'
)
expect
(
query
).
toEqual
({
first
:
'hello%20world%3Fw%3D24%26focalpoint%3Dcenter'
,
second
:
'world'
,
a
:
'b'
,
})
})
it
(
'should overwrite param values correctly'
,
async
()
=>
{
it
(
'should overwrite param values correctly'
,
async
()
=>
{
const
html
=
await
renderViaHTTP
(
appPort
,
'/test-overwrite/first/second'
)
const
html
=
await
renderViaHTTP
(
appPort
,
'/test-overwrite/first/second'
)
expect
(
html
).
toMatch
(
/this-should-be-the-value/
)
expect
(
html
).
toMatch
(
/this-should-be-the-value/
)
...
...
test/integration/production/test/security.js
View file @
4442fe2f
...
@@ -193,7 +193,7 @@ module.exports = (context) => {
...
@@ -193,7 +193,7 @@ module.exports = (context) => {
)
)
expect(res.status).toBe(307)
expect(res.status).toBe(307)
expect(pathname).toBe(encodeURI('
/
\\
google
.
com
/
about
'))
expect(pathname).toBe(encodeURI('
/
\\
google
.
com
/
about
'))
expect(hostname).
not.toBe('
google
.
com
')
expect(hostname).
toBe('
localhost
')
})
})
it('
should
handle
encoded
value
in
the
pathname
correctly
%
', async () => {
it('
should
handle
encoded
value
in
the
pathname
correctly
%
', async () => {
...
@@ -211,7 +211,28 @@ module.exports = (context) => {
...
@@ -211,7 +211,28 @@ module.exports = (context) => {
)
)
expect(res.status).toBe(307)
expect(res.status).toBe(307)
expect(pathname).toBe('
/%
25
google
.
com
/
about
')
expect(pathname).toBe('
/%
25
google
.
com
/
about
')
expect(hostname).not.toBe('
google
.
com
')
expect(hostname).toBe('
localhost
')
})
it('
should
handle
encoded
value
in
the
query
correctly
', async () => {
const res = await fetchViaHTTP(
context.appPort,
'
/
trailing
-
redirect
/
?
url
=
https
%
3
A
%
2
F
%
2
Fgoogle
.
com
%
2
Fimage
%
3
Fcrop
%
3
Dfocalpoint
%
26
w
%
3
D24
&
w
=
1200
&
q
=
100
',
undefined,
{
redirect: '
manual
',
}
)
const { pathname, hostname, query } = url.parse(
res.headers.get('
location
') || ''
)
expect(res.status).toBe(308)
expect(pathname).toBe('
/
trailing
-
redirect
')
expect(hostname).toBe('
localhost
')
expect(query).toBe(
'
url
=
https
%
3
A
%
2
F
%
2
Fgoogle
.
com
%
2
Fimage
%
3
Fcrop
%
3
Dfocalpoint
%
26
w
%
3
D24
&
w
=
1200
&
q
=
100
'
)
})
})
})
})
}
}
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