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
Boxiang Sun
gitlab-ce
Commits
15d83f6a
Commit
15d83f6a
authored
Oct 01, 2016
by
Makoto Scott-Hinkle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Filter protocol-relative URLs in ExternalLinkFilter. Fixes issue #22742.
parent
8bdecf8e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
1 deletion
+19
-1
changelogs/unreleased/22742-filter-protocol-relative-urls.yml
...gelogs/unreleased/22742-filter-protocol-relative-urls.yml
+4
-0
lib/banzai/filter/external_link_filter.rb
lib/banzai/filter/external_link_filter.rb
+1
-1
spec/lib/banzai/filter/external_link_filter_spec.rb
spec/lib/banzai/filter/external_link_filter_spec.rb
+14
-0
No files found.
changelogs/unreleased/22742-filter-protocol-relative-urls.yml
0 → 100644
View file @
15d83f6a
---
title
:
'
Filter
protocol-relative
URLs
in
ExternalLinkFilter.
Fixes
issue
#22742'
merge_request
:
6635
author
:
Makoto Scott-Hinkle
lib/banzai/filter/external_link_filter.rb
View file @
15d83f6a
...
...
@@ -10,7 +10,7 @@ module Banzai
node
.
set_attribute
(
'href'
,
href
)
end
if
href
=~
/\Ahttp(s)?:\/\//
&&
external_url?
(
href
)
if
href
=~
%r{
\A
(https?:)?//[^/]}
&&
external_url?
(
href
)
node
.
set_attribute
(
'rel'
,
'nofollow noreferrer'
)
node
.
set_attribute
(
'target'
,
'_blank'
)
end
...
...
spec/lib/banzai/filter/external_link_filter_spec.rb
View file @
15d83f6a
...
...
@@ -80,4 +80,18 @@ describe Banzai::Filter::ExternalLinkFilter, lib: true do
expect
(
filter
(
act
).
to_html
).
to
eq
(
exp
)
end
end
context
'for protocol-relative links'
do
let
(
:doc
)
{
filter
%q(<p><a href="//google.com/">Google</a></p>)
}
it
'adds rel="nofollow" to external links'
do
expect
(
doc
.
at_css
(
'a'
)).
to
have_attribute
(
'rel'
)
expect
(
doc
.
at_css
(
'a'
)[
'rel'
]).
to
include
'nofollow'
end
it
'adds rel="noreferrer" to external links'
do
expect
(
doc
.
at_css
(
'a'
)).
to
have_attribute
(
'rel'
)
expect
(
doc
.
at_css
(
'a'
)[
'rel'
]).
to
include
'noreferrer'
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