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
371ca582
Unverified
Commit
371ca582
authored
Sep 21, 2021
by
JJ Kasper
Committed by
GitHub
Sep 21, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ensure trailingSlash is correct for index with query (#29217)
parent
4a5fc41b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
113 additions
and
9 deletions
+113
-9
router.ts
packages/next/shared/lib/router/router.ts
+9
-5
basepath-trailing-slash.test.ts
test/e2e/basepath-trailing-slash.test.ts
+100
-0
basepath.test.ts
test/e2e/basepath.test.ts
+3
-3
e2e-utils.ts
test/lib/e2e-utils.ts
+1
-1
No files found.
packages/next/shared/lib/router/router.ts
View file @
371ca582
...
...
@@ -80,11 +80,15 @@ function buildCancellationError() {
}
function
addPathPrefix
(
path
:
string
,
prefix
?:
string
)
{
return
prefix
&&
path
.
startsWith
(
'/'
)
?
path
===
'/'
?
normalizePathTrailingSlash
(
prefix
)
:
`
${
prefix
}${
pathNoQueryHash
(
path
)
===
'/'
?
path
.
substring
(
1
)
:
path
}
`
:
path
if
(
!
path
.
startsWith
(
'/'
)
||
!
prefix
)
{
return
path
}
const
pathname
=
pathNoQueryHash
(
path
)
return
(
normalizePathTrailingSlash
(
`
${
prefix
}${
pathname
}
`
)
+
path
.
substr
(
pathname
.
length
)
)
}
export
function
getDomainLocale
(
...
...
test/e2e/basepath-trailing-slash.test.ts
0 → 100644
View file @
371ca582
import
{
join
}
from
'path'
import
webdriver
from
'next-webdriver'
import
{
createNext
,
FileRef
}
from
'e2e-utils'
import
{
NextInstance
}
from
'test/lib/next-modes/base'
import
{
hasRedbox
}
from
'next-test-utils'
describe
(
'basePath + trailingSlash'
,
()
=>
{
let
next
:
NextInstance
const
basePath
=
'/docs'
beforeAll
(
async
()
=>
{
next
=
await
createNext
({
files
:
{
pages
:
new
FileRef
(
join
(
__dirname
,
'basepath/pages'
)),
public
:
new
FileRef
(
join
(
__dirname
,
'basepath/public'
)),
external
:
new
FileRef
(
join
(
__dirname
,
'basepath/external'
)),
},
nextConfig
:
{
trailingSlash
:
true
,
basePath
,
onDemandEntries
:
{
// Make sure entries are not getting disposed.
maxInactiveAge
:
1000
*
60
*
60
,
},
},
})
})
afterAll
(()
=>
next
.
destroy
())
const
runTests
=
(
dev
=
false
)
=>
{
it
(
'should allow URL query strings without refresh'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
`
${
basePath
}
/hello/?query=true`
)
try
{
await
browser
.
eval
(
'window.itdidnotrefresh = "hello"'
)
await
new
Promise
((
resolve
,
reject
)
=>
{
// Timeout of EventSource created in setupPing()
// (on-demand-entries-utils.js) is 5000 ms (see #13132, #13560)
setTimeout
(
resolve
,
dev
?
10000
:
1000
)
})
expect
(
await
browser
.
eval
(
'window.itdidnotrefresh'
)).
toBe
(
'hello'
)
const
pathname
=
await
browser
.
elementByCss
(
'#pathname'
).
text
()
expect
(
pathname
).
toBe
(
'/hello'
)
expect
(
await
browser
.
eval
(
'window.location.pathname'
)).
toBe
(
`
${
basePath
}
/hello/`
)
expect
(
await
browser
.
eval
(
'window.location.search'
)).
toBe
(
'?query=true'
)
if
(
dev
)
{
expect
(
await
hasRedbox
(
browser
,
false
)).
toBe
(
false
)
}
}
finally
{
await
browser
.
close
()
}
})
it
(
'should allow URL query strings on index without refresh'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
`
${
basePath
}
/?query=true`
)
try
{
await
browser
.
eval
(
'window.itdidnotrefresh = "hello"'
)
await
new
Promise
((
resolve
,
reject
)
=>
{
// Timeout of EventSource created in setupPing()
// (on-demand-entries-utils.js) is 5000 ms (see #13132, #13560)
setTimeout
(
resolve
,
dev
?
10000
:
1000
)
})
expect
(
await
browser
.
eval
(
'window.itdidnotrefresh'
)).
toBe
(
'hello'
)
const
pathname
=
await
browser
.
elementByCss
(
'#pathname'
).
text
()
expect
(
pathname
).
toBe
(
'/'
)
expect
(
await
browser
.
eval
(
'window.location.pathname'
)).
toBe
(
basePath
+
'/'
)
expect
(
await
browser
.
eval
(
'window.location.search'
)).
toBe
(
'?query=true'
)
if
(
dev
)
{
expect
(
await
hasRedbox
(
browser
,
false
)).
toBe
(
false
)
}
}
finally
{
await
browser
.
close
()
}
})
it
(
'should correctly replace state when same asPath but different url'
,
async
()
=>
{
const
browser
=
await
webdriver
(
next
.
url
,
`
${
basePath
}
/`
)
try
{
await
browser
.
elementByCss
(
'#hello-link'
).
click
()
await
browser
.
waitForElementByCss
(
'#something-else-link'
)
await
browser
.
elementByCss
(
'#something-else-link'
).
click
()
await
browser
.
waitForElementByCss
(
'#something-else-page'
)
await
browser
.
back
()
await
browser
.
waitForElementByCss
(
'#index-page'
)
await
browser
.
forward
()
await
browser
.
waitForElementByCss
(
'#something-else-page'
)
}
finally
{
await
browser
.
close
()
}
})
}
runTests
((
global
as
any
).
isDev
)
})
test/e2e/basepath.test.ts
View file @
371ca582
...
...
@@ -13,7 +13,7 @@ import {
waitFor
,
}
from
'next-test-utils'
describe
(
'
should set-up next
'
,
()
=>
{
describe
(
'
basePath
'
,
()
=>
{
let
next
:
NextInstance
const
basePath
=
'/docs'
...
...
@@ -784,7 +784,7 @@ describe('should set-up next', () => {
await
new
Promise
((
resolve
,
reject
)
=>
{
// Timeout of EventSource created in setupPing()
// (on-demand-entries-utils.js) is 5000 ms (see #13132, #13560)
setTimeout
(
resolve
,
10
000
)
setTimeout
(
resolve
,
dev
?
10000
:
1
000
)
})
expect
(
await
browser
.
eval
(
'window.itdidnotrefresh'
)).
toBe
(
'hello'
)
...
...
@@ -810,7 +810,7 @@ describe('should set-up next', () => {
await
new
Promise
((
resolve
,
reject
)
=>
{
// Timeout of EventSource created in setupPing()
// (on-demand-entries-utils.js) is 5000 ms (see #13132, #13560)
setTimeout
(
resolve
,
10
000
)
setTimeout
(
resolve
,
dev
?
10000
:
1
000
)
})
expect
(
await
browser
.
eval
(
'window.itdidnotrefresh'
)).
toBe
(
'hello'
)
...
...
test/lib/e2e-utils.ts
View file @
371ca582
...
...
@@ -25,7 +25,7 @@ const testModeFromFile = testFolderModes.find((mode) =>
if
(
testModeFromFile
===
'e2e'
)
{
const
validE2EModes
=
[
'dev'
,
'start'
,
'deploy'
]
if
(
!
process
.
env
.
NEXT_TEST_JOB
)
{
if
(
!
process
.
env
.
NEXT_TEST_JOB
&&
!
testMode
)
{
console
.
warn
(
'Warn: no NEXT_TEST_MODE set, using default of start'
)
testMode
=
'start'
}
...
...
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