@@ -7,8 +7,8 @@ import * as vscode from 'vscode';
7
7
import { IMdParser } from '../../markdownEngine' ;
8
8
import { ITextDocument } from '../../types/textDocument' ;
9
9
import { Mime } from '../../util/mimes' ;
10
- import { createInsertUriListEdit } from './shared' ;
11
10
import { Schemes } from '../../util/schemes' ;
11
+ import { createInsertUriListEdit } from './shared' ;
12
12
13
13
export enum PasteUrlAsMarkdownLink {
14
14
Always = 'always' ,
@@ -59,7 +59,7 @@ class PasteUrlEditProvider implements vscode.DocumentPasteEditProvider {
59
59
return ;
60
60
}
61
61
62
- const edit = createInsertUriListEdit ( document , ranges , uriText ) ;
62
+ const edit = createInsertUriListEdit ( document , ranges , uriText , { preserveAbsoluteUris : true } ) ;
63
63
if ( ! edit ) {
64
64
return ;
65
65
}
@@ -212,8 +212,10 @@ const externalUriSchemes: ReadonlySet<string> = new Set([
212
212
export function findValidUriInText ( text : string ) : string | undefined {
213
213
const trimmedUrlList = text . trim ( ) ;
214
214
215
- // Uri must consist of a single sequence of characters without spaces
216
- if ( ! / ^ \S + $ / . test ( trimmedUrlList ) ) {
215
+ if (
216
+ ! / ^ \S + $ / . test ( trimmedUrlList ) // Uri must consist of a single sequence of characters without spaces
217
+ || ! trimmedUrlList . includes ( ':' ) // And it must have colon somewhere for the scheme. We will verify the schema again later
218
+ ) {
217
219
return ;
218
220
}
219
221
@@ -225,7 +227,21 @@ export function findValidUriInText(text: string): string | undefined {
225
227
return ;
226
228
}
227
229
228
- if ( ! externalUriSchemes . has ( uri . scheme . toLowerCase ( ) ) || uri . authority . length <= 1 ) {
230
+ // `Uri.parse` is lenient and will return a `file:` uri even for non-uri text such as `abc`
231
+ // Make sure that the resolved scheme starts the original text
232
+ if ( ! trimmedUrlList . toLowerCase ( ) . startsWith ( uri . scheme . toLowerCase ( ) + ':' ) ) {
233
+ return ;
234
+ }
235
+
236
+ // Only enable for an allow list of schemes. Otherwise this can be accidentally activated for non-uri text
237
+ // such as `c:\abc` or `value:foo`
238
+ if ( ! externalUriSchemes . has ( uri . scheme . toLowerCase ( ) ) ) {
239
+ return ;
240
+ }
241
+
242
+ // Some part of the uri must not be empty
243
+ // This disables the feature for text such as `http:`
244
+ if ( ! uri . authority && uri . path . length < 2 && ! uri . query && ! uri . fragment ) {
229
245
return ;
230
246
}
231
247
0 commit comments