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
522f2b2c
Commit
522f2b2c
authored
Apr 21, 2016
by
Robert Speicher
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'dev/master' into 'master'
parents
c22c4048
1ea2408b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
5 deletions
+17
-5
lib/banzai/filter/external_link_filter.rb
lib/banzai/filter/external_link_filter.rb
+2
-3
spec/features/markdown_spec.rb
spec/features/markdown_spec.rb
+6
-1
spec/lib/banzai/filter/external_link_filter_spec.rb
spec/lib/banzai/filter/external_link_filter_spec.rb
+9
-1
No files found.
lib/banzai/filter/external_link_filter.rb
View file @
522f2b2c
module
Banzai
module
Filter
# HTML Filter to add a `rel="nofollow"` attribute to external links
#
# HTML Filter to modify the attributes of external links
class
ExternalLinkFilter
<
HTML
::
Pipeline
::
Filter
def
call
doc
.
search
(
'a'
).
each
do
|
node
|
...
...
@@ -15,7 +14,7 @@ module Banzai
# Skip internal links
next
if
link
.
start_with?
(
internal_url
)
node
.
set_attribute
(
'rel'
,
'nofollow'
)
node
.
set_attribute
(
'rel'
,
'nofollow
noreferrer
'
)
end
doc
...
...
spec/features/markdown_spec.rb
View file @
522f2b2c
...
...
@@ -165,7 +165,12 @@ describe 'GitLab Markdown', feature: true do
describe
'ExternalLinkFilter'
do
it
'adds nofollow to external link'
do
link
=
doc
.
at_css
(
'a:contains("Google")'
)
expect
(
link
.
attr
(
'rel'
)).
to
match
'nofollow'
expect
(
link
.
attr
(
'rel'
)).
to
include
(
'nofollow'
)
end
it
'adds noreferrer to external link'
do
link
=
doc
.
at_css
(
'a:contains("Google")'
)
expect
(
link
.
attr
(
'rel'
)).
to
include
(
'noreferrer'
)
end
it
'ignores internal link'
do
...
...
spec/lib/banzai/filter/external_link_filter_spec.rb
View file @
522f2b2c
...
...
@@ -24,6 +24,14 @@ describe Banzai::Filter::ExternalLinkFilter, lib: true do
doc
=
filter
(
act
)
expect
(
doc
.
at_css
(
'a'
)).
to
have_attribute
(
'rel'
)
expect
(
doc
.
at_css
(
'a'
)[
'rel'
]).
to
eq
'nofollow'
expect
(
doc
.
at_css
(
'a'
)[
'rel'
]).
to
include
'nofollow'
end
it
'adds rel="noreferrer" to external links'
do
act
=
%q(<a href="https://google.com/">Google</a>)
doc
=
filter
(
act
)
expect
(
doc
.
at_css
(
'a'
)).
to
have_attribute
(
'rel'
)
expect
(
doc
.
at_css
(
'a'
)[
'rel'
]).
to
include
'noreferrer'
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