Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Invalid character in header ["Content-Disposition"] #30287

Merged
merged 35 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4255589
Image content disposition
ihmpavel Oct 25, 2021
47faa32
Merge branch 'canary' into image-content-disposition
ihmpavel Oct 25, 2021
1fb9cd3
Merge branch 'vercel:canary' into image-content-disposition
ihmpavel Oct 26, 2021
aa3c0f4
Merge branch 'vercel:canary' into image-content-disposition
ihmpavel Oct 26, 2021
7947c6e
Merge branch 'vercel:canary' into image-content-disposition
ihmpavel Oct 27, 2021
f6ae8fa
Merge branch 'vercel:canary' into image-content-disposition
ihmpavel Oct 27, 2021
41a9498
Add tests
ihmpavel Oct 27, 2021
ee35e8a
Merge branch 'vercel:canary' into image-content-disposition
ihmpavel Oct 27, 2021
4890abd
Fixed import
ihmpavel Oct 27, 2021
182215f
Add TS types
ihmpavel Oct 27, 2021
c653c1b
Merge branch 'vercel:canary' into image-content-disposition
ihmpavel Oct 27, 2021
4ee0cbb
Merge branch 'vercel:canary' into image-content-disposition
ihmpavel Oct 27, 2021
863e5da
Merge branch 'vercel:canary' into image-content-disposition
ihmpavel Oct 27, 2021
4263c42
Merge branch 'canary' into image-content-disposition
ihmpavel Oct 27, 2021
4bd86d4
Revert readme.md
styfle Oct 27, 2021
936957c
Alphabet sorting
ihmpavel Oct 28, 2021
ec6c619
Merge branch 'canary' into image-content-disposition
styfle Oct 29, 2021
6c72dad
Compile `content-disposition`
ihmpavel Oct 29, 2021
c020afd
Merge branch 'vercel:canary' into image-content-disposition
ihmpavel Oct 29, 2021
b00f778
Merge branch 'image-content-disposition' of https://github.com/ihmpav…
ihmpavel Oct 29, 2021
15e5e76
Rename for tests
ihmpavel Oct 29, 2021
76c5ab1
Merge branch 'canary' into image-content-disposition
ihmpavel Oct 29, 2021
0c7c66b
Merge branch 'canary' into image-content-disposition
ihmpavel Oct 29, 2021
9625f99
Merge branch 'canary' into image-content-disposition
ihmpavel Oct 30, 2021
a3843f6
Merge branch 'canary' into image-content-disposition
ihmpavel Oct 30, 2021
5d2f50f
Merge branch 'canary' into image-content-disposition
ihmpavel Oct 30, 2021
bb3a824
Merge branch 'canary' into image-content-disposition
ihmpavel Oct 30, 2021
cf77cfc
Merge branch 'canary' into image-content-disposition
ihmpavel Oct 31, 2021
8acaeac
Merge branch 'canary' into image-content-disposition
ihmpavel Oct 31, 2021
6aab04b
Merge branch 'canary' into image-content-disposition
ihmpavel Nov 1, 2021
93e6798
Merge branch 'canary' into image-content-disposition
styfle Nov 1, 2021
4e41255
Fix test
ihmpavel Nov 1, 2021
4060b94
Merge branch 'canary' into image-content-disposition
ihmpavel Nov 1, 2021
700f0f1
Merge branch 'canary' into image-content-disposition
kodiakhq[bot] Nov 1, 2021
8e13629
Fix accidentally added letter
ihmpavel Nov 1, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions packages/next/compiled/content-disposition/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2014-2017 Douglas Christopher Wilson

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions packages/next/compiled/content-disposition/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/next/compiled/content-disposition/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"content-disposition","main":"index.js","author":"Douglas Christopher Wilson <doug@somethingdoug.com>","license":"MIT"}
2 changes: 2 additions & 0 deletions packages/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"@types/babel__traverse": "7.11.0",
"@types/ci-info": "2.0.0",
"@types/compression": "0.0.36",
"@types/content-disposition": "0.5.4",
"@types/content-type": "1.1.3",
"@types/cookie": "0.3.3",
"@types/cross-spawn": "6.0.0",
Expand Down Expand Up @@ -203,6 +204,7 @@
"comment-json": "3.0.3",
"compression": "1.7.4",
"conf": "5.0.0",
"content-disposition": "0.5.3",
"content-type": "1.0.4",
"cookie": "0.4.1",
"cross-spawn": "6.0.5",
Expand Down
6 changes: 5 additions & 1 deletion packages/next/server/image-optimizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import imageSizeOf from 'image-size'
import { IncomingMessage, ServerResponse } from 'http'
// @ts-ignore no types for is-animated
import isAnimated from 'next/dist/compiled/is-animated'
import contentDisposition from 'next/dist/compiled/content-disposition'
styfle marked this conversation as resolved.
Show resolved Hide resolved
import { join } from 'path'
import Stream from 'stream'
import nodeUrl, { UrlWithParsedQuery } from 'url'
Expand Down Expand Up @@ -541,7 +542,10 @@ function setResponseHeaders(

const fileName = getFileNameWithExtension(url, contentType)
if (fileName) {
res.setHeader('Content-Disposition', `inline; filename="${fileName}"`)
res.setHeader(
'Content-Disposition',
contentDisposition(fileName, { type: 'inline' })
)
}

res.setHeader('Content-Security-Policy', `script-src 'none'; sandbox;`)
Expand Down
11 changes: 11 additions & 0 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,16 @@ export async function ncc_conf(task, opts) {
.target('compiled/conf')
}
// eslint-disable-next-line camelcase
externals['content-disposition'] = 'next/dist/compiled/content-disposition'
export async function ncc_content_disposition(task, opts) {
await task
.source(
opts.src || relative(__dirname, require.resolve('content-disposition'))
)
.ncc({ packageName: 'content-disposition', externals })
.target('compiled/content-disposition')
}
// eslint-disable-next-line camelcase
externals['content-type'] = 'next/dist/compiled/content-type'
export async function ncc_content_type(task, opts) {
await task
Expand Down Expand Up @@ -929,6 +939,7 @@ export async function ncc(task, opts) {
'ncc_comment_json',
'ncc_compression',
'ncc_conf',
'ncc_content_disposition',
'ncc_content_type',
'ncc_cookie',
'ncc_cross_spawn',
Expand Down
4 changes: 4 additions & 0 deletions packages/next/types/misc.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ declare module 'next/dist/compiled/conf' {
import m from 'conf'
export = m
}
declare module 'next/dist/compiled/content-disposition' {
import m from 'content-disposition'
styfle marked this conversation as resolved.
Show resolved Hide resolved
export = m
}
declare module 'next/dist/compiled/content-type' {
import m from 'content-type'
export = m
Expand Down
6 changes: 3 additions & 3 deletions test/integration/image-component/unicode/pages/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import React from 'react'
import Image from 'next/image'
import img from '../public/äöü.png'
import img from '../public/äöüščří.png'

const Page = () => {
return (
<div>
<h1>Unicode Image URL</h1>
<Image id="static" src={img} />
<Image id="internal" src="/äöü.png" width={400} height={400} />
<Image id="internal" src="/äöüščří.png" width={400} height={400} />
<Image
id="external"
src="https://image-optimization-test.vercel.app/äöü.png"
src="https://image-optimization-test.vercel.app/äöüščří.png"
width={400}
height={400}
/>
Expand Down
10 changes: 7 additions & 3 deletions test/integration/image-component/unicode/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ let browser
function runTests() {
it('should load static unicode image', async () => {
const src = await browser.elementById('static').getAttribute('src')
expect(src).toMatch(/_next%2Fstatic%2Fmedia%2F%C3%A4%C3%B6%C3%BC(.+)png/)
expect(src).toMatch(
/_next%2Fstatic%2Fmedia%2F%C3%A4%C3%B6%C3%BC%C5%A1%C4%8D%C5%99%C3%ADC(.+)png/
ihmpavel marked this conversation as resolved.
Show resolved Hide resolved
)
const fullSrc = new URL(src, `http://localhost:${appPort}`)
const res = await fetch(fullSrc)
expect(res.status).toBe(200)
})

it('should load internal unicode image', async () => {
const src = await browser.elementById('internal').getAttribute('src')
expect(src).toMatch('/_next/image?url=%2F%C3%A4%C3%B6%C3%BC.png')
expect(src).toMatch(
'/_next/image?url=%2F%C3%A4%C3%B6%C3%BC%C5%A1%C4%8D%C5%99%C3%ADC.png'
)
const fullSrc = new URL(src, `http://localhost:${appPort}`)
const res = await fetch(fullSrc)
expect(res.status).toBe(200)
Expand All @@ -37,7 +41,7 @@ function runTests() {
it('should load external unicode image', async () => {
const src = await browser.elementById('external').getAttribute('src')
expect(src).toMatch(
'/_next/image?url=https%3A%2F%2Fimage-optimization-test.vercel.app%2F%C3%A4%C3%B6%C3%BC.png'
'/_next/image?url=https%3A%2F%2Fimage-optimization-test.vercel.app%2F%C3%A4%C3%B6%C3%BC%C5%A1%C4%8D%C5%99%C3%ADC.png'
)
const fullSrc = new URL(src, `http://localhost:${appPort}`)
const res = await fetch(fullSrc)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/image-optimizer/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function runTests({
})

it('should handle non-ascii characters in image url', async () => {
const query = { w, q: 90, url: '/äöü.png' }
const query = { w, q: 90, url: '/äöüščří.png' }
const res = await fetchViaHTTP(appPort, '/_next/image', query, {})
expect(res.status).toBe(200)
})
Expand Down
6 changes: 6 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4498,6 +4498,11 @@
dependencies:
"@types/node" "*"

"@types/content-disposition@0.5.4":
version "0.5.4"
resolved "https://registry.yarnpkg.com/@types/content-disposition/-/content-disposition-0.5.4.tgz#de48cf01c79c9f1560bcfd8ae43217ab028657f8"
integrity sha512-0mPF08jn9zYI0n0Q/Pnz7C4kThdSt+6LD4amsrYDDpgBfrVWa3TcCOxKX1zkGgYniGagRv8heN2cbh+CAn+uuQ==

"@types/content-type@1.1.3":
version "1.1.3"
resolved "https://registry.yarnpkg.com/@types/content-type/-/content-type-1.1.3.tgz#3688bd77fc12f935548eef102a4e34c512b03a07"
Expand Down Expand Up @@ -7483,6 +7488,7 @@ contains-path@^0.1.0:
content-disposition@0.5.3:
version "0.5.3"
resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.3.tgz#e130caf7e7279087c5616c2007d0485698984fbd"
integrity sha512-ExO0774ikEObIAEV9kDo50o+79VCUdEB6n6lzKgGwupcVeRlhrj3qGAfwq8G6uBJjkqLrhT0qEYFcWng8z1z0g==
dependencies:
safe-buffer "5.1.2"

Expand Down