Repository: microsoft/vscode (TypeScript)
Date: 2022-10-24 10:38:18+00:00
Task type: Bug Fix

Issue:
Invalid ctrl+click links
Vscodes ctrl+click links now consumes `"`, causing it to open an invalid url
(unless the link starts right after a `"` )
Notice how the `"` at the end of the first link is underlined
clicking it takes me to `https://github.com/jeff-hykin/better-c-syntax/blob/master/autogenerated/c.tmLanguage.json"`, which is invalid

![image](https://user-images.githubusercontent.com/33529441/182323225-3f0f6d83-e9ea-4e7d-993e-b4e5db126f98.png)


Issue discussion:
The links are generated by the textual link detector

What's interesting here is:
If the string is just a link
```
		"https://github.com/jeff-hykin/better-c-syntax/blob/master/autogenerated/c.tmLanguage.json"
```
the link does not include the quote.

If it has content after the starting quote, it includes the final quote.

```
		" https://github.com/jeff-hykin/better-c-syntax/blob/master/autogenerated/c.tmLanguage.json"
```

![image](https://user-images.githubusercontent.com/6461412/186411067-cec5e747-c244-495b-a26c-c600a7d37df4.png)

I am experiencing the same thing, with single quotes in the terminal. Here are some tests/replication steps you can run in a bash terminal:
```
echo "URL: http://example.com works because it is bare"
echo "URL: 'http://example.com' works because it is wrapped in single quotes"
echo "URL: http://example.com' DOES NOT WORK because the trailing single quote is attached"
```

It's not clear to me if this an error in vscode or [xterm](https://github.com/xtermjs/xterm.js).
The current implementation of the link parser considers `"` or `'` to be stop characters only when the link began with such a quote character. Making quotes always be stop characters in link parsing would end up re-opening https://github.com/microsoft/vscode/issues/17939 where the request was that:
```
let url = `http://***/_api/web/lists/GetByTitle('Teambuildingaanvragen')/items`
```
be identified as a link

Solution patch:
diff --git a/src/vs/editor/common/languages/linkComputer.ts b/src/vs/editor/common/languages/linkComputer.ts
--- a/src/vs/editor/common/languages/linkComputer.ts
+++ b/src/vs/editor/common/languages/linkComputer.ts
@@ -258,15 +258,19 @@ export class LinkComputer {
 						case CharCode.CloseCurlyBrace:
 							chClass = (hasOpenCurlyBracket ? CharacterClass.None : CharacterClass.ForceTermination);
 							break;
-						/* The following three rules make it that ' or " or ` are allowed inside links if the link didn't begin with them */
+
+						// The following three rules make it that ' or " or ` are allowed inside links
+						// only if the link is wrapped by some other quote character
 						case CharCode.SingleQuote:
-							chClass = (linkBeginChCode === CharCode.SingleQuote ? CharacterClass.ForceTermination : CharacterClass.None);
-							break;
 						case CharCode.DoubleQuote:
-							chClass = (linkBeginChCode === CharCode.DoubleQuote ? CharacterClass.ForceTermination : CharacterClass.None);
-							break;
 						case CharCode.BackTick:
-							chClass = (linkBeginChCode === CharCode.BackTick ? CharacterClass.ForceTermination : CharacterClass.None);
+							if (linkBeginChCode === chCode) {
+								chClass = CharacterClass.ForceTermination;
+							} else if (linkBeginChCode === CharCode.SingleQuote || linkBeginChCode === CharCode.DoubleQuote || linkBeginChCode === CharCode.BackTick) {
+								chClass = CharacterClass.None;
+							} else {
+								chClass = CharacterClass.ForceTermination;
+							}
 							break;
 						case CharCode.Asterisk:
 							// `*` terminates a link if the link began with `*`


Test patch:
diff --git a/src/vs/editor/test/common/modes/linkComputer.test.ts b/src/vs/editor/test/common/modes/linkComputer.test.ts
--- a/src/vs/editor/test/common/modes/linkComputer.test.ts
+++ b/src/vs/editor/test/common/modes/linkComputer.test.ts
@@ -259,10 +259,18 @@ suite('Editor Modes - Link Computer', () => {
 		);
 	});
 
-	test('issue #151631: Link parsing stoped where comments include a single quote ', () => {
-		assertLink(
-			`aa https://regexper.com/#%2F''%2F aa`,
-			`   https://regexper.com/#%2F''%2F   `,
+	// Removed because of #156875
+	// test('issue #151631: Link parsing stoped where comments include a single quote ', () => {
+	// 	assertLink(
+	// 		`aa https://regexper.com/#%2F''%2F aa`,
+	// 		`   https://regexper.com/#%2F''%2F   `,
+	// 	);
+	// });
+
+	test('issue #156875: Links include quotes ', () => {
+		assertLink(
+			`"This file has been converted from https://github.com/jeff-hykin/better-c-syntax/blob/master/autogenerated/c.tmLanguage.json",`,
+			`                                   https://github.com/jeff-hykin/better-c-syntax/blob/master/autogenerated/c.tmLanguage.json  `,
 		);
 	});
 });