diff --git a/packages/next/next-server/lib/router/router.ts b/packages/next/next-server/lib/router/router.ts index 23ea0bc9ba4e6..fc600e82424ea 100644 --- a/packages/next/next-server/lib/router/router.ts +++ b/packages/next/next-server/lib/router/router.ts @@ -115,23 +115,6 @@ function prepareUrlAs(router: NextRouter, url: Url, as: Url) { } } -function tryParseRelativeUrl( - url: string -): null | ReturnType { - try { - return parseRelativeUrl(url) - } catch (err) { - if (process.env.NODE_ENV !== 'production') { - setTimeout(() => { - throw new Error( - `Invalid href passed to router: ${url} https://err.sh/vercel/next.js/invalid-href-passed` - ) - }, 0) - } - return null - } -} - export type BaseRouter = { route: string pathname: string @@ -503,9 +486,7 @@ export default class Router implements BaseRouter { const pages = await this.pageLoader.getPageList() const { __rewrites: rewrites } = await this.pageLoader.promisedBuildManifest - let parsed = tryParseRelativeUrl(url) - - if (!parsed) return false + let parsed = parseRelativeUrl(url) let { pathname, searchParams } = parsed @@ -899,9 +880,7 @@ export default class Router implements BaseRouter { asPath: string = url, options: PrefetchOptions = {} ): Promise { - let parsed = tryParseRelativeUrl(url) - - if (!parsed) return + let parsed = parseRelativeUrl(url) let { pathname } = parsed diff --git a/test/integration/invalid-href/test/index.test.js b/test/integration/invalid-href/test/index.test.js index 3fdc794bdfd9e..7bbf22b9d836e 100644 --- a/test/integration/invalid-href/test/index.test.js +++ b/test/integration/invalid-href/test/index.test.js @@ -135,6 +135,12 @@ describe('Invalid hrefs', () => { const $ = cheerio.load(await res.text()) expect($('#click-me').attr('href')).toBe('https://') }) + + it('renders a link with mailto: href', async () => { + const res = await fetchViaHTTP(appPort, '/first') + const $ = cheerio.load(await res.text()) + expect($('#click-me').attr('href')).toBe('mailto:idk@idk.com') + }) }) describe('dev mode', () => {