未验证 提交 f8bc67cb 编写于 作者: K kodiakhq[bot] 提交者: GitHub

Merge branch 'canary' into img-data-proto-unoptimize

......@@ -43,7 +43,7 @@ The following is the definition of the `router` object returned by both [`useRou
- `pathname`: `String` - Current route. That is the path of the page in `/pages`
- `query`: `Object` - The query string parsed to an object. It will be an empty object during prerendering if the page doesn't have [data fetching requirements](/docs/basic-features/data-fetching.md). Defaults to `{}`
- `asPath`: `String` - Actual path (including the query) shown in the browser.
- `asPath`: `String` - The path (including the query) shown in the browser without the configured `basePath` or `locale`.
- `isFallback`: `boolean` - Whether the current page is in [fallback mode](/docs/basic-features/data-fetching#fallback-pages).
- `basePath`: `String` - The active [basePath](/docs/api-reference/next.config.js/basepath) (if enabled).
- `locale`: `String` - The active locale (if enabled).
......
......@@ -578,14 +578,20 @@ function defaultLoader({ root, src, width, quality }: LoaderProps): string {
)
}
if (src && !src.startsWith('/') && configDomains) {
if (src.startsWith('//')) {
throw new Error(
`Failed to parse src "${src}" on \`next/image\`, protocol-relative URL (//) must be changed to an absolute URL (http:// or https://)`
)
}
if (!src.startsWith('/') && configDomains) {
let parsedSrc: URL
try {
parsedSrc = new URL(src)
} catch (err) {
console.error(err)
throw new Error(
`Failed to parse "${src}" in "next/image", if using relative image it must start with a leading slash "/" or be an absolute URL (http:// or https://)`
`Failed to parse src "${src}" on \`next/image\`, if using relative image it must start with a leading slash "/" or be an absolute URL (http:// or https://)`
)
}
......
import React from 'react'
import Image from 'next/image'
const Page = () => {
return (
<div>
<p>Invalid Protocol Relative Source</p>
<Image src="//assets.example.com/img.jpg" width="10" height="10" />
</div>
)
}
export default Page
......@@ -320,6 +320,15 @@ function runTests(mode) {
)
})
it('should show invalid src error when protocol-relative', async () => {
const browser = await webdriver(appPort, '/invalid-src-proto-relative')
await hasRedbox(browser)
expect(await getRedboxHeader(browser)).toContain(
'Failed to parse src "//assets.example.com/img.jpg" on `next/image`, protocol-relative URL (//) must be changed to an absolute URL (http:// or https://)'
)
})
it('should show invalid unsized error', async () => {
const browser = await webdriver(appPort, '/invalid-unsized')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册