File tree Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Expand file tree Collapse file tree 2 files changed +60
-1
lines changed Original file line number Diff line number Diff line change @@ -92,11 +92,58 @@ function lookupMimeType(ext?: string): string | undefined {
9292 return extensionToMimeType [ ext ] ;
9393}
9494
95+ const supportedProtocols = [
96+ "http:" ,
97+ "https:" ,
98+ "ftp:" ,
99+ "ftps:" ,
100+ "mailto:" ,
101+ "tel:" ,
102+ "sms:" ,
103+ "geo:" ,
104+ "file:" ,
105+ "ipfs:" ,
106+ "data:" ,
107+ "blob:" ,
108+ "chrome:" ,
109+ "chrome-extension:" ,
110+ "magnet:" ,
111+ "bitcoin:" ,
112+ "callto:" ,
113+ "dict:" ,
114+ "dns:" ,
115+ "feed:" ,
116+ "git:" ,
117+ "gtalk:" ,
118+ "imap:" ,
119+ "im:" ,
120+ "info:" ,
121+ "irc:" ,
122+ "ircs:" ,
123+ "irc6:" ,
124+ "itms:" ,
125+ "jabber:" ,
126+ "ldap:" ,
127+ "ldaps:" ,
128+ "maps:" ,
129+ "nfs:" ,
130+ "payto:" ,
131+ "proxy:" ,
132+ "redis:" ,
133+ "s3:" ,
134+ "ssh:" ,
135+ "udp:" ,
136+ "view-source:" ,
137+ "ws:" ,
138+ "wss:" ,
139+ "xmpp:" ,
140+ ] ;
141+
95142export function inferUri ( value : string ) : JSONURIFormat | undefined {
96143 try {
97144 const url = new URL ( value ) ;
98145
99- if ( url . hostname === "" ) {
146+ if ( url . hostname === "" && ! supportedProtocols . includes ( url . protocol ) ) {
100147 return undefined ;
101148 }
102149
Original file line number Diff line number Diff line change @@ -448,6 +448,7 @@ describe("uris", () => {
448448 "https://www.example.com/foo#bar" ,
449449 "file://host/path" ,
450450 "https://goole.com?hello=world" ,
451+ "ipfs://bafybeihzwwtl65z6ftqf5avmg3iv45umxm4hyz6wty4l4pd5eplnz256xa" ,
451452 ] ) ( "%p should be inferred as a rfc3986 URI" , ( value ) => {
452453 expect ( inferType ( value ) ) . toEqual ( {
453454 name : "string" ,
@@ -494,6 +495,17 @@ describe("uris", () => {
494495 contentType : "image/png" ,
495496 } ,
496497 } ) ;
498+
499+ expect (
500+ inferType ( "ipfs://bafybeihzwwtl65z6ftqf5avmg3iv45umxm4hyz6wty4l4pd5eplnz256xa/500.png" ) ,
501+ ) . toEqual ( {
502+ name : "string" ,
503+ value : "ipfs://bafybeihzwwtl65z6ftqf5avmg3iv45umxm4hyz6wty4l4pd5eplnz256xa/500.png" ,
504+ format : {
505+ name : "uri" ,
506+ contentType : "image/png" ,
507+ } ,
508+ } ) ;
497509 } ) ;
498510} ) ;
499511
You can’t perform that action at this time.
0 commit comments