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 {
92
92
return extensionToMimeType [ ext ] ;
93
93
}
94
94
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
+
95
142
export function inferUri ( value : string ) : JSONURIFormat | undefined {
96
143
try {
97
144
const url = new URL ( value ) ;
98
145
99
- if ( url . hostname === "" ) {
146
+ if ( url . hostname === "" && ! supportedProtocols . includes ( url . protocol ) ) {
100
147
return undefined ;
101
148
}
102
149
Original file line number Diff line number Diff line change @@ -448,6 +448,7 @@ describe("uris", () => {
448
448
"https://www.example.com/foo#bar" ,
449
449
"file://host/path" ,
450
450
"https://goole.com?hello=world" ,
451
+ "ipfs://bafybeihzwwtl65z6ftqf5avmg3iv45umxm4hyz6wty4l4pd5eplnz256xa" ,
451
452
] ) ( "%p should be inferred as a rfc3986 URI" , ( value ) => {
452
453
expect ( inferType ( value ) ) . toEqual ( {
453
454
name : "string" ,
@@ -494,6 +495,17 @@ describe("uris", () => {
494
495
contentType : "image/png" ,
495
496
} ,
496
497
} ) ;
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
+ } ) ;
497
509
} ) ;
498
510
} ) ;
499
511
You can’t perform that action at this time.
0 commit comments