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
4a03bbe4
Commit
4a03bbe4
authored
May 30, 2014
by
Marin Jankovski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add nofollow to all internal links.
parent
3910b591
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
7 deletions
+43
-7
app/helpers/application_helper.rb
app/helpers/application_helper.rb
+20
-7
spec/helpers/application_helper_spec.rb
spec/helpers/application_helper_spec.rb
+23
-0
No files found.
app/helpers/application_helper.rb
View file @
4a03bbe4
...
...
@@ -233,16 +233,29 @@ module ApplicationHelper
end
def
link_to
(
name
=
nil
,
options
=
nil
,
html_options
=
nil
,
&
block
)
begin
uri
=
URI
(
options
)
host
=
uri
.
host
absolute_uri
=
uri
.
absolute?
rescue
URI
::
InvalidURIError
,
ArgumentError
host
=
nil
absolute_uri
=
nil
end
# Add "nofollow" only to external links
if
host
&&
host
!=
Gitlab
.
config
.
gitlab
.
host
&&
absolute_uri
if
html_options
if
html_options
[
:rel
]
html_options
[
:rel
]
<<
" noreferrer
"
html_options
[
:rel
]
<<
" nofollow
"
else
html_options
.
merge
(
rel:
"noreferrer
"
)
html_options
.
merge!
(
rel:
"nofollow
"
)
end
else
html_options
=
Hash
.
new
html_options
[
:rel
]
=
"noreferrer
"
html_options
[
:rel
]
=
"nofollow
"
end
end
super
end
end
spec/helpers/application_helper_spec.rb
View file @
4a03bbe4
...
...
@@ -195,4 +195,27 @@ describe ApplicationHelper do
simple_sanitize
(
input
).
should
==
a_tag
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 re=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 preserver 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
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