Commit 95a90926 authored by Alfredo Sumaran's avatar Alfredo Sumaran Committed by Alejandro Rodríguez

Merge branch '25286-customer-label-doesn-t-autocomplete-correctly' into 'master'

Correct autocomplete for values with special characters

This adds a check for any special chars in any value passed to the `DefaultOptions.beforeInsert` callback function. If special chars are found and `skipSpecialCharTest` option is `false`, it will wrap the value in quotation marks.

This fixed autocompleting `~customer+` instead of `~"customer+"`.

![2016-12-03_10.37.11](/uploads/59159623638939933d23b447692775b8/2016-12-03_10.37.11.gif)

- [ ] [Changelog entry](https://docs.gitlab.com/ce/development/changelog.html) added
- [ ] [Documentation created/updated](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/development/doc_styleguide.md)
- [ ] API support added
- Tests
  - [ ] Added for this feature/bug
  - [ ] All builds are passing
- [ ] Conform by the [merge request performance guides](http://docs.gitlab.com/ce/development/merge_request_performance_guidelines.html)
- [ ] Conform by the [style guides](https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CONTRIBUTING.md#style-guides)
- [ ] Branch has no merge conflicts with `master` (if it does - rebase it please)
- [ ] [Squashed related commits together](https://git-scm.com/book/en/Git-Tools-Rewriting-History#Squashing-Commits)

Closes #25286, #24961

See merge request !7910
parent 5d793da1
...@@ -48,6 +48,10 @@ ...@@ -48,6 +48,10 @@
return $.fn.atwho["default"].callbacks.filter(query, data, searchKey); return $.fn.atwho["default"].callbacks.filter(query, data, searchKey);
}, },
beforeInsert: function(value) { beforeInsert: function(value) {
if (value && !this.setting.skipSpecialCharacterTest) {
var withoutAt = value.substring(1);
if (withoutAt && /[^\w\d]/.test(withoutAt)) value = value.charAt() + '"' + withoutAt + '"';
}
if (!GitLab.GfmAutoComplete.dataLoaded) { if (!GitLab.GfmAutoComplete.dataLoaded) {
return this.at; return this.at;
} else { } else {
...@@ -91,6 +95,7 @@ ...@@ -91,6 +95,7 @@
})(this), })(this),
insertTpl: ':${name}:', insertTpl: ':${name}:',
data: ['loading'], data: ['loading'],
skipSpecialCharacterTest: true,
callbacks: { callbacks: {
sorter: this.DefaultOptions.sorter, sorter: this.DefaultOptions.sorter,
filter: this.DefaultOptions.filter, filter: this.DefaultOptions.filter,
...@@ -113,6 +118,7 @@ ...@@ -113,6 +118,7 @@
searchKey: 'search', searchKey: 'search',
data: ['loading'], data: ['loading'],
alwaysHighlightFirst: true, alwaysHighlightFirst: true,
skipSpecialCharacterTest: true,
callbacks: { callbacks: {
sorter: this.DefaultOptions.sorter, sorter: this.DefaultOptions.sorter,
filter: this.DefaultOptions.filter, filter: this.DefaultOptions.filter,
...@@ -188,10 +194,11 @@ ...@@ -188,10 +194,11 @@
} }
}; };
})(this), })(this),
insertTpl: '${atwho-at}"${title}"', insertTpl: '${atwho-at}${title}',
data: ['loading'], data: ['loading'],
callbacks: { callbacks: {
sorter: this.DefaultOptions.sorter, sorter: this.DefaultOptions.sorter,
beforeInsert: this.DefaultOptions.beforeInsert,
beforeSave: function(milestones) { beforeSave: function(milestones) {
return $.map(milestones, function(m) { return $.map(milestones, function(m) {
if (m.title == null) { if (m.title == null) {
...@@ -247,18 +254,11 @@ ...@@ -247,18 +254,11 @@
insertTpl: '${atwho-at}${title}', insertTpl: '${atwho-at}${title}',
callbacks: { callbacks: {
sorter: this.DefaultOptions.sorter, sorter: this.DefaultOptions.sorter,
beforeInsert: this.DefaultOptions.beforeInsert,
beforeSave: function(merges) { beforeSave: function(merges) {
var sanitizeLabelTitle;
sanitizeLabelTitle = function(title) {
if (/[\w\?&]+\s+[\w\?&]+/g.test(title)) {
return "\"" + (gl.utils.sanitize(title)) + "\"";
} else {
return gl.utils.sanitize(title);
}
};
return $.map(merges, function(m) { return $.map(merges, function(m) {
return { return {
title: sanitizeLabelTitle(m.title), title: sanitize(m.title),
color: m.color, color: m.color,
search: "" + m.title search: "" + m.title
}; };
...@@ -271,6 +271,7 @@ ...@@ -271,6 +271,7 @@
at: '/', at: '/',
alias: 'commands', alias: 'commands',
searchKey: 'search', searchKey: 'search',
skipSpecialCharacterTest: true,
displayTpl: function(value) { displayTpl: function(value) {
var tpl = '<li>/${name}'; var tpl = '<li>/${name}';
if (value.aliases.length > 0) { if (value.aliases.length > 0) {
......
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