Commit a0431b51 authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab-ce master

parents 0df90142 f38e3f2f
...@@ -468,7 +468,10 @@ class GfmAutoComplete { ...@@ -468,7 +468,10 @@ class GfmAutoComplete {
// We can ignore this for quick actions because they are processed // We can ignore this for quick actions because they are processed
// before Markdown. // before Markdown.
if (!this.setting.skipMarkdownCharacterTest) { if (!this.setting.skipMarkdownCharacterTest) {
withoutAt = withoutAt.replace(/([~\-_*`])/g, '\\$&'); withoutAt = withoutAt
.replace(/(~~|`|\*)/g, '\\$1')
.replace(/(\b)(_+)/g, '$1\\$2') // only escape underscores at the start
.replace(/(_+)(\b)/g, '\\$1$2'); // or end of words
} }
return `${at}${withoutAt}`; return `${at}${withoutAt}`;
......
---
title: Only escape Markdown emphasis characters in autocomplete when necessary
merge_request: 27457
author:
type: changed
...@@ -94,7 +94,7 @@ describe('GfmAutoComplete', () => { ...@@ -94,7 +94,7 @@ describe('GfmAutoComplete', () => {
}); });
it('should quote if value contains any non-alphanumeric characters', () => { it('should quote if value contains any non-alphanumeric characters', () => {
expect(beforeInsert(atwhoInstance, '~label-20')).toBe('~"label\\-20"'); expect(beforeInsert(atwhoInstance, '~label-20')).toBe('~"label-20"');
expect(beforeInsert(atwhoInstance, '~label 20')).toBe('~"label 20"'); expect(beforeInsert(atwhoInstance, '~label 20')).toBe('~"label 20"');
}); });
...@@ -102,12 +102,21 @@ describe('GfmAutoComplete', () => { ...@@ -102,12 +102,21 @@ describe('GfmAutoComplete', () => {
expect(beforeInsert(atwhoInstance, '~1234')).toBe('~"1234"'); expect(beforeInsert(atwhoInstance, '~1234')).toBe('~"1234"');
}); });
it('should escape Markdown emphasis characters, except in the first character', () => { it('escapes Markdown strikethroughs when needed', () => {
expect(beforeInsert(atwhoInstance, '@_group')).toEqual('@\\_group'); expect(beforeInsert(atwhoInstance, '~a~bug')).toEqual('~"a~bug"');
expect(beforeInsert(atwhoInstance, '~_bug')).toEqual('~\\_bug'); expect(beforeInsert(atwhoInstance, '~a~~bug~~')).toEqual('~"a\\~~bug\\~~"');
});
it('escapes Markdown emphasis when needed', () => {
expect(beforeInsert(atwhoInstance, '~a_bug_')).toEqual('~a_bug\\_');
expect(beforeInsert(atwhoInstance, '~a _bug_')).toEqual('~"a \\_bug\\_"');
expect(beforeInsert(atwhoInstance, '~a*bug*')).toEqual('~"a\\*bug\\*"');
expect(beforeInsert(atwhoInstance, '~a *bug*')).toEqual('~"a \\*bug\\*"');
});
it('escapes Markdown code spans when needed', () => {
expect(beforeInsert(atwhoInstance, '~a`bug`')).toEqual('~"a\\`bug\\`"');
expect(beforeInsert(atwhoInstance, '~a `bug`')).toEqual('~"a \\`bug\\`"'); expect(beforeInsert(atwhoInstance, '~a `bug`')).toEqual('~"a \\`bug\\`"');
expect(beforeInsert(atwhoInstance, '~a ~bug')).toEqual('~"a \\~bug"');
expect(beforeInsert(atwhoInstance, '~a **bug')).toEqual('~"a \\*\\*bug"');
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment