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 metadata image route encoding #49482

Merged
merged 2 commits into from
May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,11 @@ const contentType = ${JSON.stringify(getContentType(resourcePath))}
const buffer = Buffer.from(${JSON.stringify(
(
await fs.promises.readFile(
resourcePath.replace(METADATA_RESOURCE_QUERY, ''),
{
encoding: 'utf-8',
}
resourcePath.replace(METADATA_RESOURCE_QUERY, '')
)
).toString()
)})
).toString('base64')
)}, 'base64'
)

export function GET() {
return new NextResponse(buffer, {
Expand Down
16 changes: 15 additions & 1 deletion test/e2e/app-dir/metadata/metadata.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { createNextDescribe } from 'e2e-utils'
import { check } from 'next-test-utils'
import { BrowserInterface } from 'test/lib/browsers/base'
import fs from 'fs/promises'
import path from 'path'
import cheerio from 'cheerio'

createNextDescribe(
'app dir - metadata',
{
files: __dirname,
},
({ next, isNextDev, isNextStart }) => {
({ next, isNextDev, isNextStart, isNextDeploy }) => {
const getTitle = (browser: BrowserInterface) =>
browser.elementByCss('title').text()

Expand Down Expand Up @@ -568,6 +570,18 @@ createNextDescribe(
const icon = $('link[rel="icon"]')
expect(icon.attr('href')).toBe('/favicon.ico')
expect(icon.attr('sizes')).toBe('any')

if (!isNextDeploy) {
const faviconFileBuffer = await fs.readFile(
path.join(next.testDir, 'app/favicon.ico')
)
const faviconResponse = Buffer.from(
await next.fetch('/favicon.ico').then((res) => res.arrayBuffer())
)
return expect(
Buffer.compare(faviconResponse, faviconFileBuffer)
).toBe(0)
}
})
})

Expand Down