BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
1d5262f9
Commit
1d5262f9
authored
Mar 29, 2018
by
Phil Hughes
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'escape-autocomplete-values-for-markdown' into 'master'
Escape autocomplete results for Markdown See merge request gitlab-org/gitlab-ce!18051
parents
518c7822
78aa8c16
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
6 deletions
+28
-6
gfm_auto_complete.js
app/assets/javascripts/gfm_auto_complete.js
+14
-5
escape-autocomplete-values-for-markdown.yml
...gs/unreleased/escape-autocomplete-values-for-markdown.yml
+5
-0
gfm_auto_complete_spec.js
spec/javascripts/gfm_auto_complete_spec.js
+9
-1
No files found.
app/assets/javascripts/gfm_auto_complete.js
View file @
1d5262f9
...
...
@@ -54,6 +54,7 @@ class GfmAutoComplete {
alias
:
'commands'
,
searchKey
:
'search'
,
skipSpecialCharacterTest
:
true
,
skipMarkdownCharacterTest
:
true
,
data
:
GfmAutoComplete
.
defaultLoadingData
,
displayTpl
(
value
)
{
if
(
GfmAutoComplete
.
isLoading
(
value
))
return
GfmAutoComplete
.
Loading
.
template
;
...
...
@@ -376,15 +377,23 @@ class GfmAutoComplete {
return
$
.
fn
.
atwho
.
default
.
callbacks
.
filter
(
query
,
data
,
searchKey
);
},
beforeInsert
(
value
)
{
let
resultantValue
=
value
;
let
withoutAt
=
value
.
substring
(
1
);
const
at
=
value
.
charAt
();
if
(
value
&&
!
this
.
setting
.
skipSpecialCharacterTest
)
{
const
withoutAt
=
value
.
substring
(
1
);
const
regex
=
value
.
charAt
()
===
'~'
?
/
\W
|^
\d
+$/
:
/
\W
/
;
const
regex
=
at
===
'~'
?
/
\W
|^
\d
+$/
:
/
\W
/
;
if
(
withoutAt
&&
regex
.
test
(
withoutAt
))
{
resultantValue
=
`
${
value
.
charAt
()}
"
${
withoutAt
}
"`
;
withoutAt
=
`
"
${
withoutAt
}
"`
;
}
}
return
resultantValue
;
// We can ignore this for quick actions because they are processed
// before Markdown.
if
(
!
this
.
setting
.
skipMarkdownCharacterTest
)
{
withoutAt
=
withoutAt
.
replace
(
/
([
~
\-
_*`
])
/g
,
'
\\
$&'
);
}
return
`
${
at
}${
withoutAt
}
`
;
},
matcher
(
flag
,
subtext
)
{
const
match
=
GfmAutoComplete
.
defaultMatcher
(
flag
,
subtext
,
this
.
app
.
controllers
);
...
...
changelogs/unreleased/escape-autocomplete-values-for-markdown.yml
0 → 100644
View file @
1d5262f9
---
title
:
Escape Markdown characters properly when using autocomplete
merge_request
:
author
:
type
:
fixed
spec/javascripts/gfm_auto_complete_spec.js
View file @
1d5262f9
...
...
@@ -81,13 +81,21 @@ describe('GfmAutoComplete', function () {
});
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"'
);
});
it
(
'should quote integer labels'
,
()
=>
{
expect
(
beforeInsert
(
atwhoInstance
,
'~1234'
)).
toBe
(
'~"1234"'
);
});
it
(
'should escape Markdown emphasis characters, except in the first character'
,
()
=>
{
expect
(
beforeInsert
(
atwhoInstance
,
'@_group'
)).
toEqual
(
'@
\\
_group'
);
expect
(
beforeInsert
(
atwhoInstance
,
'~_bug'
)).
toEqual
(
'~
\\
_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"'
);
});
});
describe
(
'DefaultOptions.matcher'
,
function
()
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment