mirror of
https://github.com/renovatebot/renovate.git
synced 2026-10-25 06:51:11 +00:00
fix(util/markdown): preserve at signs in URLs (#45555)
This commit is contained in:
@@ -110,5 +110,15 @@ describe('util/markdown', () => {
|
||||
'mention @​user here',
|
||||
);
|
||||
});
|
||||
|
||||
it('should not add zero-width space to @ inside URLs', async () => {
|
||||
const input =
|
||||
'Read more at https://medium.com/@fastifyjs/fastify-v4-ga-59f2103b5f0e by @user';
|
||||
const linkified = await linkify(input, { repository: 'some/repo' });
|
||||
|
||||
expect(sanitizeMarkdown(linkified)).toEqual(
|
||||
'Read more at <https://medium.com/@fastifyjs/fastify-v4-ga-59f2103b5f0e> by [@​user](https://github.com/user)\n',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,11 +10,13 @@ export function sanitizeMarkdown(markdown: string): string {
|
||||
// Put a zero width space after every # followed by a digit
|
||||
res = res.replace(regEx(/(\W)#(\d)/gi), '$1#​$2');
|
||||
// Put a zero width space after every @ symbol to prevent unintended hyperlinking,
|
||||
// but leave code blocks (triple backticks) and inline code spans untouched
|
||||
// but leave URLs, code blocks (triple backticks), and inline code spans untouched
|
||||
res = res
|
||||
.split(regEx(/(```[\s\S]*?```|`[^`\n]*?`)/g))
|
||||
.split(regEx(/(```[\s\S]*?```|`[^`\n]*?`|https?:\/\/[^\s<]+)/gi))
|
||||
.map((part) =>
|
||||
part.startsWith('`') ? part : part.replace(regEx(/@/g), '@​'),
|
||||
part.startsWith('`') || regEx(/^https?:\/\//i).test(part)
|
||||
? part
|
||||
: part.replace(regEx(/@/g), '@​'),
|
||||
)
|
||||
.join('');
|
||||
res = res.replace(regEx(/([a-z]@)​/gi), '$1');
|
||||
|
||||
Reference in New Issue
Block a user