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
54365ecc
Commit
54365ecc
authored
Jun 17, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove overridden `link_to` helper
The purpose for this override is now handled by `ExternalLinkFilter`.
parent
e12b6431
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
0 additions
and
70 deletions
+0
-70
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+0
-33
spec/helpers/application_helper_spec.rb
spec/helpers/application_helper_spec.rb
+0
-37
No files found.
app/helpers/application_helper.rb
View file @
54365ecc
...
@@ -214,39 +214,6 @@ module ApplicationHelper
...
@@ -214,39 +214,6 @@ module ApplicationHelper
Gitlab
::
MarkupHelper
.
asciidoc?
(
filename
)
Gitlab
::
MarkupHelper
.
asciidoc?
(
filename
)
end
end
# Overrides ActionView::Helpers::UrlHelper#link_to to add `rel="nofollow"` to
# external links
def
link_to
(
name
=
nil
,
options
=
nil
,
html_options
=
{})
if
options
.
kind_of?
(
String
)
if
!
options
.
start_with?
(
'#'
,
'/'
)
html_options
=
add_nofollow
(
options
,
html_options
)
end
end
super
end
# Add `"rel=nofollow"` to external links
#
# link - String link to check
# html_options - Hash of `html_options` passed to `link_to`
#
# Returns `html_options`, adding `rel: nofollow` for external links
def
add_nofollow
(
link
,
html_options
=
{})
begin
uri
=
URI
(
link
)
if
uri
&&
uri
.
absolute?
&&
uri
.
host
!=
Gitlab
.
config
.
gitlab
.
host
rel
=
html_options
.
fetch
(
:rel
,
''
)
html_options
[
:rel
]
=
(
rel
+
' nofollow'
).
strip
end
rescue
URI
::
Error
# noop
end
html_options
end
def
promo_host
def
promo_host
'about.gitlab.com'
'about.gitlab.com'
end
end
...
...
spec/helpers/application_helper_spec.rb
View file @
54365ecc
...
@@ -203,43 +203,6 @@ describe ApplicationHelper do
...
@@ -203,43 +203,6 @@ describe ApplicationHelper do
end
end
end
end
describe
'link_to'
do
it
'should not include rel=nofollow for internal links'
do
expect
(
link_to
(
'Home'
,
root_path
)).
to
eq
(
'<a href="/">Home</a>'
)
end
it
'should include rel=nofollow for external links'
do
expect
(
link_to
(
'Example'
,
'http://www.example.com'
)).
to
eq
'<a href="http://www.example.com" rel="nofollow">Example</a>'
end
it
'should include rel=nofollow for external links and honor existing html_options'
do
expect
(
link_to
(
'Example'
,
'http://www.example.com'
,
class:
'toggle'
,
data:
{
toggle:
'dropdown'
}))
.
to
eq
'<a class="toggle" data-toggle="dropdown" href="http://www.example.com" rel="nofollow">Example</a>'
end
it
'should include rel=nofollow for external links and preserve other rel values'
do
expect
(
link_to
(
'Example'
,
'http://www.example.com'
,
rel:
'noreferrer'
))
.
to
eq
'<a href="http://www.example.com" rel="noreferrer nofollow">Example</a>'
end
it
'should not include rel=nofollow for external links on the same host as GitLab'
do
expect
(
Gitlab
.
config
.
gitlab
).
to
receive
(
:host
).
and_return
(
'example.foo'
)
expect
(
link_to
(
'Example'
,
'http://example.foo/bar'
)).
to
eq
'<a href="http://example.foo/bar">Example</a>'
end
it
'should not raise an error when given a bad URI'
do
expect
{
link_to
(
'default'
,
'if real=1 RANDOM; if real>1 IDLHS; if real>500 LHS'
)
}.
not_to
raise_error
end
it
'should not raise an error when given a bad mailto URL'
do
expect
{
link_to
(
'email'
,
'mailto://foo.bar@example.es?subject=Subject%20Line'
)
}.
not_to
raise_error
end
end
describe
'render_markup'
do
describe
'render_markup'
do
let
(
:content
)
{
'Noël'
}
let
(
:content
)
{
'Noël'
}
...
...
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