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
Tatuya Kamada
gitlab-ce
Commits
f682c097
Commit
f682c097
authored
Jul 12, 2016
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix markdown rendering for label references that begin with a digit
parent
c88075f4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
1 deletion
+52
-1
app/models/label.rb
app/models/label.rb
+4
-1
spec/lib/banzai/filter/label_reference_filter_spec.rb
spec/lib/banzai/filter/label_reference_filter_spec.rb
+48
-0
No files found.
app/models/label.rb
View file @
f682c097
...
@@ -52,11 +52,14 @@ class Label < ActiveRecord::Base
...
@@ -52,11 +52,14 @@ class Label < ActiveRecord::Base
# This pattern supports cross-project references.
# This pattern supports cross-project references.
#
#
def
self
.
reference_pattern
def
self
.
reference_pattern
# NOTE: The id pattern only matches when all characters on the expression
# are digits, so it will match ~2 but not ~2fa because that's probably a
# label name and we want it to be matched as such.
@reference_pattern
||=
%r{
@reference_pattern
||=
%r{
(
#{
Project
.
reference_pattern
}
)?
(
#{
Project
.
reference_pattern
}
)?
#{
Regexp
.
escape
(
reference_prefix
)
}
#{
Regexp
.
escape
(
reference_prefix
)
}
(?:
(?:
(?<label_id>
\d
+) | # Integer-based label ID, or
(?<label_id>
\d
+
(?!
\S\w
)
\b
) | # Integer-based label ID, or
(?<label_name>
(?<label_name>
[A-Za-z0-9_
\-\?
&]+ | # String-based single-word label title, or
[A-Za-z0-9_
\-\?
&]+ | # String-based single-word label title, or
"([^"]*)" # String-based multi-word label surrounded in quotes
"([^"]*)" # String-based multi-word label surrounded in quotes
...
...
spec/lib/banzai/filter/label_reference_filter_spec.rb
View file @
f682c097
...
@@ -104,6 +104,30 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
...
@@ -104,6 +104,30 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end
end
end
end
context
'String-based single-word references that begin with a digit'
do
let
(
:label
)
{
create
(
:label
,
name:
'2fa'
,
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 2fa'
end
it
'links with adjacent text'
do
doc
=
reference_filter
(
"Label (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
%r(
\(
<a.+><span.+>
#{
label
.
name
}
</span></a>
\.\)
)
)
end
it
'ignores invalid label names'
do
exp
=
act
=
"Label
#{
Label
.
reference_prefix
}#{
label
.
id
}#{
label
.
name
.
reverse
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'String-based single-word references with special characters'
do
context
'String-based single-word references with special characters'
do
let
(
:label
)
{
create
(
:label
,
name:
'?gfm&'
,
project:
project
)
}
let
(
:label
)
{
create
(
:label
,
name:
'?gfm&'
,
project:
project
)
}
let
(
:reference
)
{
"
#{
Label
.
reference_prefix
}#{
label
.
name
}
"
}
let
(
:reference
)
{
"
#{
Label
.
reference_prefix
}#{
label
.
name
}
"
}
...
@@ -153,6 +177,30 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
...
@@ -153,6 +177,30 @@ describe Banzai::Filter::LabelReferenceFilter, lib: true do
end
end
end
end
context
'String-based multi-word references that begin with a digit'
do
let
(
:label
)
{
create
(
:label
,
name:
'2 factor authentication'
,
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 2 factor authentication'
end
it
'links with adjacent text'
do
doc
=
reference_filter
(
"Label (
#{
reference
}
.)"
)
expect
(
doc
.
to_html
).
to
match
(
%r(
\(
<a.+><span.+>
#{
label
.
name
}
</span></a>
\.\)
)
)
end
it
'ignores invalid label names'
do
exp
=
act
=
"Label
#{
Label
.
reference_prefix
}#{
label
.
id
}#{
label
.
name
.
reverse
}
"
expect
(
reference_filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'String-based multi-word references with special characters in quotes'
do
context
'String-based multi-word references with special characters in quotes'
do
let
(
:label
)
{
create
(
:label
,
name:
'gfm & references?'
,
project:
project
)
}
let
(
:label
)
{
create
(
:label
,
name:
'gfm & references?'
,
project:
project
)
}
let
(
:reference
)
{
label
.
to_reference
(
format: :name
)
}
let
(
:reference
)
{
label
.
to_reference
(
format: :name
)
}
...
...
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