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
Kazuhiko Shiozaki
gitlab-ce
Commits
212fe14c
Commit
212fe14c
authored
May 20, 2015
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Customize the sanitization whitelist only once
Fixes #1651
parent
71b1a2c7
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
13 deletions
+22
-13
lib/gitlab/markdown/sanitization_filter.rb
lib/gitlab/markdown/sanitization_filter.rb
+22
-13
No files found.
lib/gitlab/markdown/sanitization_filter.rb
View file @
212fe14c
...
@@ -8,28 +8,33 @@ module Gitlab
...
@@ -8,28 +8,33 @@ module Gitlab
# Extends HTML::Pipeline::SanitizationFilter with a custom whitelist.
# Extends HTML::Pipeline::SanitizationFilter with a custom whitelist.
class
SanitizationFilter
<
HTML
::
Pipeline
::
SanitizationFilter
class
SanitizationFilter
<
HTML
::
Pipeline
::
SanitizationFilter
def
whitelist
def
whitelist
whitelist
=
HTML
::
Pipeline
::
SanitizationFilter
::
WHITELIST
whitelist
=
super
# Allow code highlighting
# Only push these customizations once
whitelist
[
:attributes
][
'pre'
]
=
%w(class)
unless
customized?
(
whitelist
[
:transformers
])
whitelist
[
:attributes
][
'span'
]
=
%w(class)
# Allow code highlighting
whitelist
[
:attributes
][
'pre'
]
=
%w(class)
whitelist
[
:attributes
][
'span'
]
=
%w(class)
# Allow table alignment
# Allow table alignment
whitelist
[
:attributes
][
'th'
]
=
%w(style)
whitelist
[
:attributes
][
'th'
]
=
%w(style)
whitelist
[
:attributes
][
'td'
]
=
%w(style)
whitelist
[
:attributes
][
'td'
]
=
%w(style)
# Allow span elements
# Allow span elements
whitelist
[
:elements
].
push
(
'span'
)
whitelist
[
:elements
].
push
(
'span'
)
# Remove `rel` attribute from `a` elements
# Remove `rel` attribute from `a` elements
whitelist
[
:transformers
].
push
(
remove_rel
)
whitelist
[
:transformers
].
push
(
remove_rel
)
# Remove `class` attribute from non-highlight spans
# Remove `class` attribute from non-highlight spans
whitelist
[
:transformers
].
push
(
clean_spans
)
whitelist
[
:transformers
].
push
(
clean_spans
)
end
whitelist
whitelist
end
end
private
def
remove_rel
def
remove_rel
lambda
do
|
env
|
lambda
do
|
env
|
if
env
[
:node_name
]
==
'a'
if
env
[
:node_name
]
==
'a'
...
@@ -48,6 +53,10 @@ module Gitlab
...
@@ -48,6 +53,10 @@ module Gitlab
end
end
end
end
end
end
def
customized?
(
transformers
)
transformers
.
last
.
source_location
[
0
]
==
__FILE__
end
end
end
end
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