Skip to content

Commit

Permalink
Fix metadata image route encoding (#49482)
Browse files Browse the repository at this point in the history
Fix the bad encoded buffer introduced in #49323
  • Loading branch information
huozhi committed May 8, 2023
1 parent 00ed2ba commit b20d5f2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
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

0 comments on commit b20d5f2

Please sign in to comment.