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
Léo-Paul Géneau
gitlab-ce
Commits
81a09bc7
Commit
81a09bc7
authored
May 15, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support only double quotes for multi-word label references
parent
35853033
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
53 deletions
+33
-53
app/models/label.rb
app/models/label.rb
+4
-6
lib/gitlab/markdown/label_reference_filter.rb
lib/gitlab/markdown/label_reference_filter.rb
+1
-2
spec/lib/gitlab/markdown/label_reference_filter_spec.rb
spec/lib/gitlab/markdown/label_reference_filter_spec.rb
+14
-40
spec/models/label_spec.rb
spec/models/label_spec.rb
+14
-5
No files found.
app/models/label.rb
View file @
81a09bc7
...
@@ -41,16 +41,14 @@ class Label < ActiveRecord::Base
...
@@ -41,16 +41,14 @@ class Label < ActiveRecord::Base
end
end
# Pattern used to extract label references from text
# Pattern used to extract label references from text
#
# TODO (rspeicher): Limit to double quotes (meh) or disallow single quotes in label names (bad).
def
self
.
reference_pattern
def
self
.
reference_pattern
%r{
%r{
#{
reference_prefix
}
#{
reference_prefix
}
(?:
(?:
(?<label_id>
\d
+) | # Integer-based label ID, or
(?<label_id>
\d
+) | # Integer-based label ID, or
(?<label_name>
(?<label_name>
[A-Za-z0-9_-]+
| # String-based single-word label title
[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
)
)
)
)
}x
}x
...
@@ -70,7 +68,7 @@ class Label < ActiveRecord::Base
...
@@ -70,7 +68,7 @@ class Label < ActiveRecord::Base
#
#
# Returns a String
# Returns a String
def
to_reference
(
format
=
:id
)
def
to_reference
(
format
=
:id
)
if
format
==
:name
if
format
==
:name
&&
!
name
.
include?
(
'"'
)
%(#{self.class.reference_prefix}"#{name}")
%(#{self.class.reference_prefix}"#{name}")
else
else
"
#{
self
.
class
.
reference_prefix
}#{
id
}
"
"
#{
self
.
class
.
reference_prefix
}#{
id
}
"
...
...
lib/gitlab/markdown/label_reference_filter.rb
View file @
81a09bc7
...
@@ -72,8 +72,7 @@ module Gitlab
...
@@ -72,8 +72,7 @@ module Gitlab
# Returns a Hash.
# Returns a Hash.
def
label_params
(
id
,
name
)
def
label_params
(
id
,
name
)
if
name
if
name
# TODO (rspeicher): Don't strip single quotes if we decide to only use double quotes for surrounding.
{
name:
name
.
tr
(
'"'
,
''
)
}
{
name:
name
.
tr
(
'\'"'
,
''
)
}
else
else
{
id:
id
}
{
id:
id
}
end
end
...
...
spec/lib/gitlab/markdown/label_reference_filter_spec.rb
View file @
81a09bc7
...
@@ -101,32 +101,7 @@ module Gitlab::Markdown
...
@@ -101,32 +101,7 @@ module Gitlab::Markdown
context
'String-based multi-word references in quotes'
do
context
'String-based multi-word references 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
(
:name
)
}
context
'in single quotes'
do
let
(
:reference
)
{
"
#{
Label
.
reference_prefix
}
'
#{
label
.
name
}
'"
}
it
'links to a valid reference'
do
doc
=
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
=
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
.
name
.
reverse
}
'"
expect
(
filter
(
act
).
to_html
).
to
eq
exp
end
end
context
'in double quotes'
do
let
(
:reference
)
{
%(#{Label.reference_prefix}"#{label.name}")
}
it
'links to a valid reference'
do
it
'links to a valid reference'
do
doc
=
filter
(
"See
#{
reference
}
"
)
doc
=
filter
(
"See
#{
reference
}
"
)
...
@@ -147,7 +122,6 @@ module Gitlab::Markdown
...
@@ -147,7 +122,6 @@ module Gitlab::Markdown
expect
(
filter
(
act
).
to_html
).
to
eq
exp
expect
(
filter
(
act
).
to_html
).
to
eq
exp
end
end
end
end
end
describe
'edge cases'
do
describe
'edge cases'
do
it
'gracefully handles non-references matching the pattern'
do
it
'gracefully handles non-references matching the pattern'
do
...
...
spec/models/label_spec.rb
View file @
81a09bc7
...
@@ -55,13 +55,22 @@ describe Label do
...
@@ -55,13 +55,22 @@ describe Label do
end
end
describe
'#to_reference'
do
describe
'#to_reference'
do
context
'using id'
do
it
'returns a String reference to the object'
do
it
'returns a String reference to the object'
do
expect
(
label
.
to_reference
).
to
eq
"~
#{
label
.
id
}
"
expect
(
label
.
to_reference
).
to
eq
"~
#{
label
.
id
}
"
expect
(
label
.
to_reference
(
double
)).
to
eq
"~
#{
label
.
id
}
"
expect
(
label
.
to_reference
(
double
(
'project'
))).
to
eq
"~
#{
label
.
id
}
"
end
end
end
it
'returns a String reference to the object using its name'
do
context
'using name'
do
it
'returns a String reference to the object'
do
expect
(
label
.
to_reference
(
:name
)).
to
eq
%(~"#{label.name}")
expect
(
label
.
to_reference
(
:name
)).
to
eq
%(~"#{label.name}")
end
end
it
'uses id when name contains double quote'
do
label
=
create
(
:label
,
name:
%q{"irony"}
)
expect
(
label
.
to_reference
(
:name
)).
to
eq
"~
#{
label
.
id
}
"
end
end
end
end
end
end
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