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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
32e63ba7
Commit
32e63ba7
authored
Aug 06, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add `data-[type]-id` attribute to reference links
This is to let us redact them later in another filter.
parent
5fb5fd25
Changes
15
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
96 additions
and
8 deletions
+96
-8
lib/gitlab/markdown/commit_range_reference_filter.rb
lib/gitlab/markdown/commit_range_reference_filter.rb
+2
-1
lib/gitlab/markdown/commit_reference_filter.rb
lib/gitlab/markdown/commit_reference_filter.rb
+2
-1
lib/gitlab/markdown/issue_reference_filter.rb
lib/gitlab/markdown/issue_reference_filter.rb
+2
-1
lib/gitlab/markdown/label_reference_filter.rb
lib/gitlab/markdown/label_reference_filter.rb
+2
-1
lib/gitlab/markdown/merge_request_reference_filter.rb
lib/gitlab/markdown/merge_request_reference_filter.rb
+2
-1
lib/gitlab/markdown/reference_filter.rb
lib/gitlab/markdown/reference_filter.rb
+16
-0
lib/gitlab/markdown/snippet_reference_filter.rb
lib/gitlab/markdown/snippet_reference_filter.rb
+2
-1
lib/gitlab/markdown/user_reference_filter.rb
lib/gitlab/markdown/user_reference_filter.rb
+4
-2
spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
...lib/gitlab/markdown/commit_range_reference_filter_spec.rb
+8
-0
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
+8
-0
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
+8
-0
spec/lib/gitlab/markdown/label_reference_filter_spec.rb
spec/lib/gitlab/markdown/label_reference_filter_spec.rb
+8
-0
spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
...ib/gitlab/markdown/merge_request_reference_filter_spec.rb
+8
-0
spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
+8
-0
spec/lib/gitlab/markdown/user_reference_filter_spec.rb
spec/lib/gitlab/markdown/user_reference_filter_spec.rb
+16
-0
No files found.
lib/gitlab/markdown/commit_range_reference_filter.rb
View file @
32e63ba7
...
@@ -57,10 +57,11 @@ module Gitlab
...
@@ -57,10 +57,11 @@ module Gitlab
title
=
range
.
reference_title
title
=
range
.
reference_title
klass
=
reference_class
(
:commit_range
)
klass
=
reference_class
(
:commit_range
)
data
=
data_attribute
(
project
.
id
)
project_ref
+=
'@'
if
project_ref
project_ref
+=
'@'
if
project_ref
%(<a href="#{url}"
%(<a href="#{url}"
#{data}
title="#{title}"
title="#{title}"
class="#{klass}">#{project_ref}#{range}</a>)
class="#{klass}">#{project_ref}#{range}</a>)
else
else
...
...
lib/gitlab/markdown/commit_reference_filter.rb
View file @
32e63ba7
...
@@ -47,10 +47,11 @@ module Gitlab
...
@@ -47,10 +47,11 @@ module Gitlab
title
=
escape_once
(
commit
.
link_title
)
title
=
escape_once
(
commit
.
link_title
)
klass
=
reference_class
(
:commit
)
klass
=
reference_class
(
:commit
)
data
=
data_attribute
(
project
.
id
)
project_ref
+=
'@'
if
project_ref
project_ref
+=
'@'
if
project_ref
%(<a href="#{url}"
%(<a href="#{url}"
#{data}
title="#{title}"
title="#{title}"
class="#{klass}">#{project_ref}#{commit.short_id}</a>)
class="#{klass}">#{project_ref}#{commit.short_id}</a>)
else
else
...
...
lib/gitlab/markdown/issue_reference_filter.rb
View file @
32e63ba7
...
@@ -49,8 +49,9 @@ module Gitlab
...
@@ -49,8 +49,9 @@ module Gitlab
title
=
escape_once
(
"Issue:
#{
issue
.
title
}
"
)
title
=
escape_once
(
"Issue:
#{
issue
.
title
}
"
)
klass
=
reference_class
(
:issue
)
klass
=
reference_class
(
:issue
)
data
=
data_attribute
(
project
.
id
)
%(<a href="#{url}"
%(<a href="#{url}"
#{data}
title="#{title}"
title="#{title}"
class="#{klass}">#{match}</a>)
class="#{klass}">#{match}</a>)
else
else
...
...
lib/gitlab/markdown/label_reference_filter.rb
View file @
32e63ba7
...
@@ -43,8 +43,9 @@ module Gitlab
...
@@ -43,8 +43,9 @@ module Gitlab
url
=
url_for_label
(
project
,
label
)
url
=
url_for_label
(
project
,
label
)
klass
=
reference_class
(
:label
)
klass
=
reference_class
(
:label
)
data
=
data_attribute
(
project
.
id
)
%(<a href="#{url}"
%(<a href="#{url}"
#{data}
class="#{klass}">#{render_colored_label(label)}</a>)
class="#{klass}">#{render_colored_label(label)}</a>)
else
else
match
match
...
...
lib/gitlab/markdown/merge_request_reference_filter.rb
View file @
32e63ba7
...
@@ -47,10 +47,11 @@ module Gitlab
...
@@ -47,10 +47,11 @@ module Gitlab
title
=
escape_once
(
"Merge Request:
#{
merge_request
.
title
}
"
)
title
=
escape_once
(
"Merge Request:
#{
merge_request
.
title
}
"
)
klass
=
reference_class
(
:merge_request
)
klass
=
reference_class
(
:merge_request
)
data
=
data_attribute
(
project
.
id
)
url
=
url_for_merge_request
(
merge_request
,
project
)
url
=
url_for_merge_request
(
merge_request
,
project
)
%(<a href="#{url}"
%(<a href="#{url}"
#{data}
title="#{title}"
title="#{title}"
class="#{klass}">#{match}</a>)
class="#{klass}">#{match}</a>)
else
else
...
...
lib/gitlab/markdown/reference_filter.rb
View file @
32e63ba7
...
@@ -21,6 +21,22 @@ module Gitlab
...
@@ -21,6 +21,22 @@ module Gitlab
result
[
:references
]
=
Hash
.
new
{
|
hash
,
type
|
hash
[
type
]
=
[]
}
result
[
:references
]
=
Hash
.
new
{
|
hash
,
type
|
hash
[
type
]
=
[]
}
end
end
# Returns a data attribute String to attach to a reference link
#
# id - Object ID
# type - Object type (default: :project)
#
# Examples:
#
# data_attribute(1) # => "data-project-id=\"1\""
# data_attribute(2, :user) # => "data-user-id=\"2\""
# data_attribute(3, :group) # => "data-group-id=\"3\""
#
# Returns a String
def
data_attribute
(
id
,
type
=
:project
)
%Q(data-
#{
type
}
-id="
#{
id
}
")
end
def
escape_once
(
html
)
def
escape_once
(
html
)
ERB
::
Util
.
html_escape_once
(
html
)
ERB
::
Util
.
html_escape_once
(
html
)
end
end
...
...
lib/gitlab/markdown/snippet_reference_filter.rb
View file @
32e63ba7
...
@@ -47,10 +47,11 @@ module Gitlab
...
@@ -47,10 +47,11 @@ module Gitlab
title
=
escape_once
(
"Snippet:
#{
snippet
.
title
}
"
)
title
=
escape_once
(
"Snippet:
#{
snippet
.
title
}
"
)
klass
=
reference_class
(
:snippet
)
klass
=
reference_class
(
:snippet
)
data
=
data_attribute
(
project
.
id
)
url
=
url_for_snippet
(
snippet
,
project
)
url
=
url_for_snippet
(
snippet
,
project
)
%(<a href="#{url}"
%(<a href="#{url}"
#{data}
title="#{title}"
title="#{title}"
class="#{klass}">#{match}</a>)
class="#{klass}">#{match}</a>)
else
else
...
...
lib/gitlab/markdown/user_reference_filter.rb
View file @
32e63ba7
...
@@ -83,18 +83,20 @@ module Gitlab
...
@@ -83,18 +83,20 @@ module Gitlab
push_result
(
:user
,
*
namespace
.
users
)
push_result
(
:user
,
*
namespace
.
users
)
url
=
urls
.
group_url
(
group
,
only_path:
context
[
:only_path
])
url
=
urls
.
group_url
(
group
,
only_path:
context
[
:only_path
])
data
=
data_attribute
(
namespace
.
id
,
:group
)
text
=
Group
.
reference_prefix
+
group
text
=
Group
.
reference_prefix
+
group
%(<a href="#{url}" class="#{link_class}">#{text}</a>)
%(<a href="#{url}"
#{data}
class="#{link_class}">#{text}</a>)
end
end
def
link_to_user
(
user
,
namespace
)
def
link_to_user
(
user
,
namespace
)
push_result
(
:user
,
namespace
.
owner
)
push_result
(
:user
,
namespace
.
owner
)
url
=
urls
.
user_url
(
user
,
only_path:
context
[
:only_path
])
url
=
urls
.
user_url
(
user
,
only_path:
context
[
:only_path
])
data
=
data_attribute
(
namespace
.
owner_id
,
:user
)
text
=
User
.
reference_prefix
+
user
text
=
User
.
reference_prefix
+
user
%(<a href="#{url}" class="#{link_class}">#{text}</a>)
%(<a href="#{url}"
#{data}
class="#{link_class}">#{text}</a>)
end
end
def
user_can_reference_group?
(
group
)
def
user_can_reference_group?
(
group
)
...
...
spec/lib/gitlab/markdown/commit_range_reference_filter_spec.rb
View file @
32e63ba7
...
@@ -80,6 +80,14 @@ module Gitlab::Markdown
...
@@ -80,6 +80,14 @@ module Gitlab::Markdown
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
include
'custom'
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
include
'custom'
end
end
it
'includes a data-project-id attribute'
do
doc
=
filter
(
"See
#{
reference
}
"
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-project-id'
)
expect
(
link
.
attr
(
'data-project-id'
)).
to
eq
project
.
id
.
to_s
end
it
'supports an :only_path option'
do
it
'supports an :only_path option'
do
doc
=
filter
(
"See
#{
reference
}
"
,
only_path:
true
)
doc
=
filter
(
"See
#{
reference
}
"
,
only_path:
true
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
...
...
spec/lib/gitlab/markdown/commit_reference_filter_spec.rb
View file @
32e63ba7
...
@@ -76,6 +76,14 @@ module Gitlab::Markdown
...
@@ -76,6 +76,14 @@ module Gitlab::Markdown
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
include
'custom'
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
include
'custom'
end
end
it
'includes a data-project-id attribute'
do
doc
=
filter
(
"See
#{
reference
}
"
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-project-id'
)
expect
(
link
.
attr
(
'data-project-id'
)).
to
eq
project
.
id
.
to_s
end
it
'supports an :only_path context'
do
it
'supports an :only_path context'
do
doc
=
filter
(
"See
#{
reference
}
"
,
only_path:
true
)
doc
=
filter
(
"See
#{
reference
}
"
,
only_path:
true
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
...
...
spec/lib/gitlab/markdown/issue_reference_filter_spec.rb
View file @
32e63ba7
...
@@ -73,6 +73,14 @@ module Gitlab::Markdown
...
@@ -73,6 +73,14 @@ module Gitlab::Markdown
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
include
'custom'
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
include
'custom'
end
end
it
'includes a data-project-id attribute'
do
doc
=
filter
(
"Issue
#{
reference
}
"
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-project-id'
)
expect
(
link
.
attr
(
'data-project-id'
)).
to
eq
project
.
id
.
to_s
end
it
'supports an :only_path context'
do
it
'supports an :only_path context'
do
doc
=
filter
(
"Issue
#{
reference
}
"
,
only_path:
true
)
doc
=
filter
(
"Issue
#{
reference
}
"
,
only_path:
true
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
...
...
spec/lib/gitlab/markdown/label_reference_filter_spec.rb
View file @
32e63ba7
...
@@ -30,6 +30,14 @@ module Gitlab::Markdown
...
@@ -30,6 +30,14 @@ module Gitlab::Markdown
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
include
'custom'
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
include
'custom'
end
end
it
'includes a data-project-id attribute'
do
doc
=
filter
(
"Label
#{
reference
}
"
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-project-id'
)
expect
(
link
.
attr
(
'data-project-id'
)).
to
eq
project
.
id
.
to_s
end
it
'supports an :only_path context'
do
it
'supports an :only_path context'
do
doc
=
filter
(
"Label
#{
reference
}
"
,
only_path:
true
)
doc
=
filter
(
"Label
#{
reference
}
"
,
only_path:
true
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
...
...
spec/lib/gitlab/markdown/merge_request_reference_filter_spec.rb
View file @
32e63ba7
...
@@ -61,6 +61,14 @@ module Gitlab::Markdown
...
@@ -61,6 +61,14 @@ module Gitlab::Markdown
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
include
'custom'
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
include
'custom'
end
end
it
'includes a data-project-id attribute'
do
doc
=
filter
(
"Merge
#{
reference
}
"
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-project-id'
)
expect
(
link
.
attr
(
'data-project-id'
)).
to
eq
project
.
id
.
to_s
end
it
'supports an :only_path context'
do
it
'supports an :only_path context'
do
doc
=
filter
(
"Merge
#{
reference
}
"
,
only_path:
true
)
doc
=
filter
(
"Merge
#{
reference
}
"
,
only_path:
true
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
...
...
spec/lib/gitlab/markdown/snippet_reference_filter_spec.rb
View file @
32e63ba7
...
@@ -60,6 +60,14 @@ module Gitlab::Markdown
...
@@ -60,6 +60,14 @@ module Gitlab::Markdown
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
include
'custom'
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'class'
)).
to
include
'custom'
end
end
it
'includes a data-project-id attribute'
do
doc
=
filter
(
"Snippet
#{
reference
}
"
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-project-id'
)
expect
(
link
.
attr
(
'data-project-id'
)).
to
eq
project
.
id
.
to_s
end
it
'supports an :only_path context'
do
it
'supports an :only_path context'
do
doc
=
filter
(
"Snippet
#{
reference
}
"
,
only_path:
true
)
doc
=
filter
(
"Snippet
#{
reference
}
"
,
only_path:
true
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
link
=
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)
...
...
spec/lib/gitlab/markdown/user_reference_filter_spec.rb
View file @
32e63ba7
...
@@ -64,6 +64,14 @@ module Gitlab::Markdown
...
@@ -64,6 +64,14 @@ module Gitlab::Markdown
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
expect
(
doc
.
css
(
'a'
).
length
).
to
eq
1
end
end
it
'includes a data-user-id attribute'
do
doc
=
filter
(
"Hey
#{
reference
}
"
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-user-id'
)
expect
(
link
.
attr
(
'data-user-id'
)).
to
eq
user
.
namespace
.
owner_id
.
to_s
end
it
'adds to the results hash'
do
it
'adds to the results hash'
do
result
=
pipeline_result
(
"Hey
#{
reference
}
"
)
result
=
pipeline_result
(
"Hey
#{
reference
}
"
)
expect
(
result
[
:references
][
:user
]).
to
eq
[
user
]
expect
(
result
[
:references
][
:user
]).
to
eq
[
user
]
...
@@ -85,6 +93,14 @@ module Gitlab::Markdown
...
@@ -85,6 +93,14 @@ module Gitlab::Markdown
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
group_url
(
group
)
expect
(
doc
.
css
(
'a'
).
first
.
attr
(
'href'
)).
to
eq
urls
.
group_url
(
group
)
end
end
it
'includes a data-group-id attribute'
do
doc
=
filter
(
"Hey
#{
reference
}
"
,
current_user:
user
)
link
=
doc
.
css
(
'a'
).
first
expect
(
link
).
to
have_attribute
(
'data-group-id'
)
expect
(
link
.
attr
(
'data-group-id'
)).
to
eq
group
.
id
.
to_s
end
it
'adds to the results hash'
do
it
'adds to the results hash'
do
result
=
pipeline_result
(
"Hey
#{
reference
}
"
,
current_user:
user
)
result
=
pipeline_result
(
"Hey
#{
reference
}
"
,
current_user:
user
)
expect
(
result
[
:references
][
:user
]).
to
eq
group
.
users
expect
(
result
[
:references
][
:user
]).
to
eq
group
.
users
...
...
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