Skip to content

Commit

Permalink
Merge branch 'canary' into cli-session/next-config
Browse files Browse the repository at this point in the history
  • Loading branch information
Timer authored Feb 14, 2020
2 parents fe879d0 + ecfa7f7 commit bd5cf61
Show file tree
Hide file tree
Showing 14 changed files with 95 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"registry": "https://registry.npmjs.org/"
}
},
"version": "9.2.2-canary.19"
"version": "9.2.2-canary.20"
}
2 changes: 1 addition & 1 deletion packages/create-next-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-next-app",
"version": "9.2.2-canary.19",
"version": "9.2.2-canary.20",
"keywords": [
"react",
"next",
Expand Down
2 changes: 1 addition & 1 deletion packages/next-bundle-analyzer/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/bundle-analyzer",
"version": "9.2.2-canary.19",
"version": "9.2.2-canary.20",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-mdx/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/mdx",
"version": "9.2.2-canary.19",
"version": "9.2.2-canary.20",
"main": "index.js",
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-google-analytics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-google-analytics",
"version": "9.2.2-canary.19",
"version": "9.2.2-canary.20",
"nextjs": {
"name": "Google Analytics",
"required-env": [
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-material-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-material-ui",
"version": "9.2.2-canary.19",
"version": "9.2.2-canary.20",
"nextjs": {
"name": "Material UI",
"required-env": []
Expand Down
2 changes: 1 addition & 1 deletion packages/next-plugin-sentry/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/plugin-sentry",
"version": "9.2.2-canary.19",
"version": "9.2.2-canary.20",
"nextjs": {
"name": "Sentry",
"required-env": [
Expand Down
2 changes: 1 addition & 1 deletion packages/next-polyfill-nomodule/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@next/polyfill-nomodule",
"version": "9.2.2-canary.19",
"version": "9.2.2-canary.20",
"description": "A polyfill for non-dead, nomodule browsers.",
"main": "dist/polyfill-nomodule.js",
"license": "MIT",
Expand Down
3 changes: 2 additions & 1 deletion packages/next/next-server/server/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ export const prepareDestination = (destination: string, params: Params) => {
})

try {
newUrl = destinationCompiler(params)
newUrl = encodeURI(destinationCompiler(params))

const [pathname, hash] = newUrl.split('#')
parsedDestination.pathname = pathname
parsedDestination.hash = `${hash ? '#' : ''}${hash || ''}`
Expand Down
4 changes: 2 additions & 2 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "next",
"version": "9.2.2-canary.19",
"version": "9.2.2-canary.20",
"description": "The React Framework",
"main": "./dist/server/next.js",
"license": "MIT",
Expand Down Expand Up @@ -73,7 +73,7 @@
"@babel/preset-typescript": "7.7.2",
"@babel/runtime": "7.7.2",
"@babel/runtime-corejs2": "7.7.2",
"@next/polyfill-nomodule": "9.2.2-canary.19",
"@next/polyfill-nomodule": "9.2.2-canary.20",
"amphtml-validator": "1.0.23",
"async-retry": "1.2.3",
"async-sema": "3.0.0",
Expand Down
5 changes: 5 additions & 0 deletions test/integration/custom-routes/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ module.exports = {
},
async redirects() {
return [
{
source: '/redirect/me/to-about/:lang',
destination: '/:lang/about',
permanent: false,
},
{
source: '/docs/router-status/:code',
destination: '/docs/v2/network/status-codes#:code',
Expand Down
24 changes: 24 additions & 0 deletions test/integration/custom-routes/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,22 @@ const runTests = (isDev = false) => {
expect(JSON.parse(data)).toEqual({ query: { name: 'hello' } })
})

it('should handle encoded value in the pathname correctly', async () => {
const res = await fetchViaHTTP(
appPort,
'/redirect/me/to-about/' + encodeURI('\\google.com'),
undefined,
{
redirect: 'manual',
}
)

const { pathname, hostname } = url.parse(res.headers.get('location') || '')
expect(res.status).toBe(307)
expect(pathname).toBe(encodeURI('/\\google.com/about'))
expect(hostname).not.toBe('google.com')
})

if (!isDev) {
it('should output routes-manifest successfully', async () => {
const manifest = await fs.readJSON(
Expand All @@ -331,6 +347,14 @@ const runTests = (isDev = false) => {
pages404: false,
basePath: '',
redirects: [
{
destination: '/:lang/about',
regex: normalizeRegEx(
'^\\/redirect\\/me\\/to-about(?:\\/([^\\/]+?))$'
),
source: '/redirect/me/to-about/:lang',
statusCode: 307,
},
{
source: '/docs/router-status/:code',
destination: '/docs/v2/network/status-codes#:code',
Expand Down
11 changes: 11 additions & 0 deletions test/integration/production/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,15 @@ module.exports = {
// Make sure entries are not getting disposed.
maxInactiveAge: 1000 * 60 * 60,
},
experimental: {
redirects() {
return [
{
source: '/redirect/me/to-about/:lang',
destination: '/:lang/about',
permanent: false,
},
]
},
},
}
44 changes: 43 additions & 1 deletion test/integration/production/test/security.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
/* eslint-env jest */
import webdriver from 'next-webdriver'
import { readFileSync } from 'fs'
import url from 'url'
import { join, resolve as resolvePath } from 'path'
import { renderViaHTTP, getBrowserBodyText, waitFor } from 'next-test-utils'
import {
renderViaHTTP,
getBrowserBodyText,
waitFor,
fetchViaHTTP,
} from 'next-test-utils'
import { recursiveReadDir } from 'next/dist/lib/recursive-readdir'
import { homedir } from 'os'

Expand Down Expand Up @@ -152,5 +158,41 @@ module.exports = context => {
await checkInjected(browser)
await browser.close()
})

it('should handle encoded value in the pathname correctly \\', async () => {
const res = await fetchViaHTTP(
context.appPort,
'/redirect/me/to-about/' + encodeURI('\\google.com'),
undefined,
{
redirect: 'manual',
}
)

const { pathname, hostname } = url.parse(
res.headers.get('location') || ''
)
expect(res.status).toBe(307)
expect(pathname).toBe(encodeURI('/\\google.com/about'))
expect(hostname).not.toBe('google.com')
})

it('should handle encoded value in the pathname correctly %', async () => {
const res = await fetchViaHTTP(
context.appPort,
'/redirect/me/to-about/%25google.com',
undefined,
{
redirect: 'manual',
}
)

const { pathname, hostname } = url.parse(
res.headers.get('location') || ''
)
expect(res.status).toBe(307)
expect(pathname).toBe('/%25google.com/about')
expect(hostname).not.toBe('google.com')
})
})
}

0 comments on commit bd5cf61

Please sign in to comment.