Skip to content

Commit

Permalink
bug: allow scheme-relative url in links
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco committed Nov 15, 2021
1 parent ef57953 commit 187a406
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/shared/lib/router/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export function resolveHref(

// repeated slashes and backslashes in the URL are considered
// invalid and will never match a Next.js page/file
const urlProtoMatch = urlAsString.match(/^[a-zA-Z]{1,}:\/\//)
const urlProtoMatch = urlAsString.match(/^(?:[a-zA-Z]+:)?\/\//)
const urlAsStringNoProto = urlProtoMatch
? urlAsString.substr(urlProtoMatch[0].length)
: urlAsString
Expand Down
49 changes: 49 additions & 0 deletions test/e2e/relative-scheme-url.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { createNext } from 'e2e-utils'
import { check } from 'next-test-utils'
import webdriver from 'next-webdriver'
import { NextInstance } from 'test/lib/next-modes/base'

describe('should set-up next', () => {
let next: NextInstance

beforeAll(async () => {
next = await createNext({
files: {
'pages/index.js': `
import React from 'react'
import Link from 'next/link'
export default function Page() {
return (
<>
<Link href="//example.org">
<a>&#47;&#47;example.org</a>
</Link>
</>
)
}
`,
},
})
})
afterAll(() => next.destroy())

it('scheme-relative urls should not have the starting // merged', async () => {
const browser = await webdriver(next.url, '/')

await check(
async () => {
const links = await browser.elementsByCss('a[href]')
const link = links[0]
const href = await link.getAttribute('href')

return href === '//example.org'
},
{
test(result) {
return result === true
},
}
)
})
})

0 comments on commit 187a406

Please sign in to comment.