File tree Expand file tree Collapse file tree 4 files changed +28
-6
lines changed
test/integration/invalid-href Expand file tree Collapse file tree 4 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,8 @@ export function resolveHref(
3434
3535 // repeated slashes and backslashes in the URL are considered
3636 // invalid and will never match a Next.js page/file
37- const urlProtoMatch = urlAsString . match ( / ^ [ a - z A - Z + ] { 1 , } : \/ \/ / )
37+ // https://datatracker.ietf.org/doc/html/rfc1738#section-2.1
38+ const urlProtoMatch = urlAsString . match ( / ^ [ a - z A - Z ] [ a - z A - Z + . - ] * : \/ \/ / )
3839 const urlAsStringNoProto = urlProtoMatch
3940 ? urlAsString . slice ( urlProtoMatch [ 0 ] . length )
4041 : urlAsString
Original file line number Diff line number Diff line change 1+ import Link from 'next/link'
2+
3+ export default function Page ( ) {
4+ return (
5+ < >
6+ < Link href = "flatpak+https://dl.flathub.org/repo/appstream/net.krafting.Playlifin.flatpakref" >
7+ flatpak+https
8+ </ Link >
9+ < Link href = "com.apple.tv://" > com.apple.tv</ Link >
10+ < Link href = "itms-apps://" > itms-apps</ Link >
11+ </ >
12+ )
13+ }
Original file line number Diff line number Diff line change @@ -12,16 +12,16 @@ export default function Page() {
1212 id = "click-me"
1313 onClick = { ( e ) => {
1414 e . preventDefault ( )
15+ // this should throw an error on load since prefetch
16+ // receives the invalid href
1517 router [ method ] ( invalidLink )
1618 } }
1719 >
1820 invalid link :o
1921 </ a >
2022 ) : (
21- // this should throw an error on load since prefetch
22- // receives the invalid href
2323 < Link href = { invalidLink } id = "click-me" >
24- invalid link :o
24+ valid link :o
2525 </ Link >
2626 )
2727}
Original file line number Diff line number Diff line change @@ -98,10 +98,14 @@ describe('Invalid hrefs', () => {
9898 await noError ( '/first' )
9999 } )
100100
101- it ( 'does not show error in production when https://google.com is used as href on Link' , async ( ) => {
101+ it ( 'does not show error in production when https:// is used in href on Link' , async ( ) => {
102102 await noError ( '/second' )
103103 } )
104104
105+ it ( 'does not show error in production when exotic protocols are used in href in Link' , async ( ) => {
106+ await noError ( '/exotic-href' )
107+ } )
108+
105109 it ( 'does not show error when internal href is used with external as' , async ( ) => {
106110 await noError ( '/invalid-relative' , true )
107111 } )
@@ -160,10 +164,14 @@ describe('Invalid hrefs', () => {
160164 await noError ( '/first' )
161165 } )
162166
163- it ( 'does not show error when https://google.com is used as href on Link' , async ( ) => {
167+ it ( 'does not show error when https:// is used as href in Link' , async ( ) => {
164168 await noError ( '/second' )
165169 } )
166170
171+ it ( 'does not show error when exotic protocols are used in href in Link' , async ( ) => {
172+ await noError ( '/exotic-href' )
173+ } )
174+
167175 // eslint-disable-next-line jest/no-identical-title
168176 it ( 'shows error when dynamic route mismatch is used on Link' , async ( ) => {
169177 await showsError (
You can’t perform that action at this time.
0 commit comments