Skip to content

Commit c05297c

Browse files
authored
Make link text regexp non-greedy (microsoft#165867)
Fixes microsoft#163081
1 parent 0aa2255 commit c05297c

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/vs/base/common/linkedText.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class LinkedText {
2323
}
2424
}
2525

26-
const LINK_REGEX = /\[([^\]]+)\]\(((?:https?:\/\/|command:|file:)[^\)\s]+)(?: ("|')([^\3]+)(\3))?\)/gi;
26+
const LINK_REGEX = /\[([^\]]+)\]\(((?:https?:\/\/|command:|file:)[^\)\s]+)(?: (["'])(.+?)(\3))?\)/gi;
2727

2828
export function parseLinkedText(text: string): LinkedText {
2929
const result: LinkedTextNode[] = [];

src/vs/base/test/common/linkedText.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,14 @@ suite('LinkedText', () => {
7070
'...'
7171
]);
7272
});
73+
74+
test('Should match non-greedily', () => {
75+
assert.deepStrictEqual(parseLinkedText('a [link text 1](http://link.href "title1") b [link text 2](http://link.href "title2") c').nodes, [
76+
'a ',
77+
{ label: 'link text 1', href: 'http://link.href', title: 'title1' },
78+
' b ',
79+
{ label: 'link text 2', href: 'http://link.href', title: 'title2' },
80+
' c',
81+
]);
82+
});
7383
});

0 commit comments

Comments
 (0)