Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
ab811b6a
Commit
ab811b6a
authored
Jun 20, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Render references for labels that name contains ?, or &
parent
e186626d
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
17 deletions
+77
-17
app/assets/javascripts/gfm_auto_complete.js.coffee
app/assets/javascripts/gfm_auto_complete.js.coffee
+1
-1
app/helpers/labels_helper.rb
app/helpers/labels_helper.rb
+11
-1
app/models/label.rb
app/models/label.rb
+3
-13
lib/banzai/filter/label_reference_filter.rb
lib/banzai/filter/label_reference_filter.rb
+6
-2
spec/helpers/labels_helper_spec.rb
spec/helpers/labels_helper_spec.rb
+6
-0
spec/lib/banzai/filter/label_reference_filter_spec.rb
spec/lib/banzai/filter/label_reference_filter_spec.rb
+50
-0
No files found.
app/assets/javascripts/gfm_auto_complete.js.coffee
View file @
ab811b6a
...
...
@@ -190,7 +190,7 @@ GitLab.GfmAutoComplete =
callbacks
:
beforeSave
:
(
merges
)
->
sanitizeLabelTitle
=
(
title
)
->
if
/
\w+\s+\w
+/g
.
test
(
title
)
if
/
[\w\?&]+\s+[\w\?&]
+/g
.
test
(
title
)
"
\"
#{
sanitize
(
title
)
}
\"
"
else
sanitize
(
title
)
...
...
app/helpers/labels_helper.rb
View file @
ab811b6a
module
LabelsHelper
include
ActionView
::
Helpers
::
TagHelper
TABLE_FOR_ESCAPE_HTML_ENTITIES
=
{
'&'
=>
'&'
,
'<'
=>
'<'
,
'>'
=>
'>'
}
# Link to a Label
#
# label - Label object to link to
...
...
@@ -130,7 +136,11 @@ module LabelsHelper
label
.
subscribed?
(
current_user
)
?
'Unsubscribe'
:
'Subscribe'
end
def
unescape_html_entities
(
value
)
value
.
to_s
.
gsub
(
/(>)|(<)|(&)/
,
TABLE_FOR_ESCAPE_HTML_ENTITIES
.
invert
)
end
# Required for Banzai::Filter::LabelReferenceFilter
module_function
:render_colored_label
,
:render_colored_cross_project_label
,
:text_color_for_bg
,
:escape_once
:text_color_for_bg
,
:escape_once
,
:unescape_html_entities
end
app/models/label.rb
View file @
ab811b6a
...
...
@@ -58,8 +58,8 @@ class Label < ActiveRecord::Base
(?:
(?<label_id>
\d
+) | # Integer-based label ID, or
(?<label_name>
[A-Za-z0-9_
-
]+ | # String-based single-word label title, or
"[^
&
\?
,]+"
# String-based multi-word label surrounded in quotes
[A-Za-z0-9_
\-\?
&
]+ | # String-based single-word label title, or
"[^
,]+"
# String-based multi-word label surrounded in quotes
)
)
}x
...
...
@@ -134,16 +134,6 @@ class Label < ActiveRecord::Base
end
def
sanitize_title
(
value
)
un
nescape_html_entities
(
Sanitize
.
clean
(
value
.
to_s
))
LabelsHelper
.
u
nescape_html_entities
(
Sanitize
.
clean
(
value
.
to_s
))
end
def
unnescape_html_entities
(
value
)
value
.
to_s
.
gsub
(
/(>)|(<)|(&)/
,
Label
::
TABLE_FOR_ESCAPE_HTML_ENTITIES
.
invert
)
end
TABLE_FOR_ESCAPE_HTML_ENTITIES
=
{
'&'
=>
'&'
,
'<'
=>
'<'
,
'>'
=>
'>'
}
end
lib/banzai/filter/label_reference_filter.rb
View file @
ab811b6a
...
...
@@ -13,13 +13,13 @@ module Banzai
end
def
self
.
references_in
(
text
,
pattern
=
Label
.
reference_pattern
)
text
.
gsub
(
pattern
)
do
|
match
|
unescape_html_entities
(
text
)
.
gsub
(
pattern
)
do
|
match
|
yield
match
,
$~
[
:label_id
].
to_i
,
$~
[
:label_name
],
$~
[
:project
],
$~
end
end
def
references_in
(
text
,
pattern
=
Label
.
reference_pattern
)
text
.
gsub
(
pattern
)
do
|
match
|
unescape_html_entities
(
text
)
.
gsub
(
pattern
)
do
|
match
|
label
=
find_label
(
$~
[
:project
],
$~
[
:label_id
],
$~
[
:label_name
])
if
label
...
...
@@ -66,6 +66,10 @@ module Banzai
LabelsHelper
.
render_colored_cross_project_label
(
object
)
end
end
def
unescape_html_entities
(
text
)
LabelsHelper
.
unescape_html_entities
(
text
)
end
end
end
end
spec/helpers/labels_helper_spec.rb
View file @
ab811b6a
...
...
@@ -77,4 +77,10 @@ describe LabelsHelper do
expect
(
text_color_for_bg
(
'#000'
)).
to
eq
'#FFFFFF'
end
end
describe
'unescape_html_entities'
do
it
'decodes &, <, and > named entities'
do
expect
(
unescape_html_entities
(
'foo & bar < zoo > boo é'
)).
to
eq
'foo & bar < zoo > boo é'
end
end
end
spec/lib/banzai/filter/label_reference_filter_spec.rb
View file @
ab811b6a
...
...
@@ -104,6 +104,31 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end
end
context
'String-based single-word references with special characters'
do
let
(
:label
)
{
create
(
:label
,
name:
'?gfm&'
,
project:
project
)
}
let
(
:reference
)
{
"
#{
Label
.
reference_prefix
}#{
label
.
name
}
"
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_issues_url
(
project
.
namespace
,
project
,
label_name:
label
.
name
)
expect
(
doc
.
text
).
to
eq
'See ?gfm&'
end
it
'links with adjacent text'
do
doc
=
reference_filter
(
"Label (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
%r(
\(
<a.+><span.+>
\?
gfm&</span></a>
\.\)
)
)
end
it
'ignores invalid label names'
do
act
=
"Label
#{
Label
.
reference_prefix
}#{
label
.
name
.
reverse
}
"
exp
=
"Label
#{
Label
.
reference_prefix
}
&mfg?"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'String-based multi-word references in quotes'
do
let
(
:label
)
{
create
(
:label
,
name:
'gfm references'
,
project:
project
)
}
let
(
:reference
)
{
label
.
to_reference
(
format: :name
)
}
...
...
@@ -128,6 +153,31 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end
end
context
'String-based multi-word references with special characters in quotes'
do
let
(
:label
)
{
create
(
:label
,
name:
'gfm & references?'
,
project:
project
)
}
let
(
:reference
)
{
label
.
to_reference
(
format: :name
)
}
it
'links to a valid reference'
do
doc
=
reference_filter
(
"See
#{
reference
}
"
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
namespace_project_issues_url
(
project
.
namespace
,
project
,
label_name:
label
.
name
)
expect
(
doc
.
text
).
to
eq
'See gfm & references?'
end
it
'links with adjacent text'
do
doc
=
reference_filter
(
"Label (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
%r(
\(
<a.+><span.+>gfm & references
\?
</span></a>
\.\)
)
)
end
it
'ignores invalid label names'
do
act
=
%(Label #{Label.reference_prefix}"#{label.name.reverse}")
exp
=
%(Label #{Label.reference_prefix}"?secnerefer & mfg\")
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
describe
'edge cases'
do
it
'gracefully handles non-references matching the pattern'
do
exp
=
act
=
'(format nil "~0f" 3.0) ; 3.0'
...
...
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