Commit d2d7bfa7 authored by haseeb's avatar haseeb Committed by Filipa Lacerda

fix to allow integer label refernces

parent 2e13dafb
...@@ -338,7 +338,8 @@ class GfmAutoComplete { ...@@ -338,7 +338,8 @@ class GfmAutoComplete {
let resultantValue = value; let resultantValue = value;
if (value && !this.setting.skipSpecialCharacterTest) { if (value && !this.setting.skipSpecialCharacterTest) {
const withoutAt = value.substring(1); const withoutAt = value.substring(1);
if (withoutAt && /[^\w\d]/.test(withoutAt)) { const regex = value.charAt() === '~' ? /\W|^\d+$/ : /\W/;
if (withoutAt && regex.test(withoutAt)) {
resultantValue = `${value.charAt()}"${withoutAt}"`; resultantValue = `${value.charAt()}"${withoutAt}"`;
} }
} }
......
---
title: Fix errors when selecting numeric-only labels in the labels autocomplete selector
merge_request: 14607
author: haseebeqx
type: fixed
...@@ -218,6 +218,7 @@ feature 'GFM autocomplete', :js do ...@@ -218,6 +218,7 @@ feature 'GFM autocomplete', :js do
user_item = find('.atwho-view li', text: user.username) user_item = find('.atwho-view li', text: user.username)
expect(user_item).to have_content(user.username) expect(user_item).to have_content(user.username)
end end
end
def expect_to_wrap(should_wrap, item, note, value) def expect_to_wrap(should_wrap, item, note, value)
expect(item).to have_content(value) expect(item).to have_content(value)
...@@ -231,5 +232,4 @@ feature 'GFM autocomplete', :js do ...@@ -231,5 +232,4 @@ feature 'GFM autocomplete', :js do
expect(note.value).not_to include("\"#{value}\"") expect(note.value).not_to include("\"#{value}\"")
end end
end end
end
end end
...@@ -67,6 +67,28 @@ describe('GfmAutoComplete', function () { ...@@ -67,6 +67,28 @@ describe('GfmAutoComplete', function () {
}); });
}); });
describe('DefaultOptions.beforeInsert', () => {
const beforeInsert = (context, value) => (
gfmAutoCompleteCallbacks.beforeInsert.call(context, value)
);
const atwhoInstance = { setting: { skipSpecialCharacterTest: false } };
it('should not quote if value only contains alphanumeric charecters', () => {
expect(beforeInsert(atwhoInstance, '@user1')).toBe('@user1');
expect(beforeInsert(atwhoInstance, '~label1')).toBe('~label1');
});
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"');
});
it('should quote integer labels', () => {
expect(beforeInsert(atwhoInstance, '~1234')).toBe('~"1234"');
});
});
describe('DefaultOptions.matcher', function () { describe('DefaultOptions.matcher', function () {
const defaultMatcher = (context, flag, subtext) => ( const defaultMatcher = (context, flag, subtext) => (
gfmAutoCompleteCallbacks.matcher.call(context, flag, subtext) gfmAutoCompleteCallbacks.matcher.call(context, flag, subtext)
......
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