Skip to content

Commit a81cd28

Browse files
authored
Prefer that quotes terminate links in ambiguous cases (microsoft#164431)
Fixes microsoft#156875: Prefer that quotes terminate links in ambiguous cases
1 parent 6fb4786 commit a81cd28

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

src/vs/editor/common/languages/linkComputer.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,19 @@ export class LinkComputer {
258258
case CharCode.CloseCurlyBrace:
259259
chClass = (hasOpenCurlyBracket ? CharacterClass.None : CharacterClass.ForceTermination);
260260
break;
261-
/* The following three rules make it that ' or " or ` are allowed inside links if the link didn't begin with them */
261+
262+
// The following three rules make it that ' or " or ` are allowed inside links
263+
// only if the link is wrapped by some other quote character
262264
case CharCode.SingleQuote:
263-
chClass = (linkBeginChCode === CharCode.SingleQuote ? CharacterClass.ForceTermination : CharacterClass.None);
264-
break;
265265
case CharCode.DoubleQuote:
266-
chClass = (linkBeginChCode === CharCode.DoubleQuote ? CharacterClass.ForceTermination : CharacterClass.None);
267-
break;
268266
case CharCode.BackTick:
269-
chClass = (linkBeginChCode === CharCode.BackTick ? CharacterClass.ForceTermination : CharacterClass.None);
267+
if (linkBeginChCode === chCode) {
268+
chClass = CharacterClass.ForceTermination;
269+
} else if (linkBeginChCode === CharCode.SingleQuote || linkBeginChCode === CharCode.DoubleQuote || linkBeginChCode === CharCode.BackTick) {
270+
chClass = CharacterClass.None;
271+
} else {
272+
chClass = CharacterClass.ForceTermination;
273+
}
270274
break;
271275
case CharCode.Asterisk:
272276
// `*` terminates a link if the link began with `*`

src/vs/editor/test/common/modes/linkComputer.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,18 @@ suite('Editor Modes - Link Computer', () => {
259259
);
260260
});
261261

262-
test('issue #151631: Link parsing stoped where comments include a single quote ', () => {
263-
assertLink(
264-
`aa https://regexper.com/#%2F''%2F aa`,
265-
` https://regexper.com/#%2F''%2F `,
262+
// Removed because of #156875
263+
// test('issue #151631: Link parsing stoped where comments include a single quote ', () => {
264+
// assertLink(
265+
// `aa https://regexper.com/#%2F''%2F aa`,
266+
// ` https://regexper.com/#%2F''%2F `,
267+
// );
268+
// });
269+
270+
test('issue #156875: Links include quotes ', () => {
271+
assertLink(
272+
`"This file has been converted from https://github.com/jeff-hykin/better-c-syntax/blob/master/autogenerated/c.tmLanguage.json",`,
273+
` https://github.com/jeff-hykin/better-c-syntax/blob/master/autogenerated/c.tmLanguage.json `,
266274
);
267275
});
268276
});

0 commit comments

Comments
 (0)