Skip to content
Snippets Groups Projects
Commit 0b63bb6e authored by Robert Speicher's avatar Robert Speicher Committed by Job van der Voort
Browse files

Customize the sanitization whitelist only once

Fixes #1651
parent 98f12863
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -8,28 +8,33 @@ module Gitlab
# Extends HTML::Pipeline::SanitizationFilter with a custom whitelist.
class SanitizationFilter < HTML::Pipeline::SanitizationFilter
def whitelist
whitelist = HTML::Pipeline::SanitizationFilter::WHITELIST
whitelist = super
 
# Allow code highlighting
whitelist[:attributes]['pre'] = %w(class)
whitelist[:attributes]['span'] = %w(class)
# Only push these customizations once
unless customized?(whitelist[:transformers])
# Allow code highlighting
whitelist[:attributes]['pre'] = %w(class)
whitelist[:attributes]['span'] = %w(class)
 
# Allow table alignment
whitelist[:attributes]['th'] = %w(style)
whitelist[:attributes]['td'] = %w(style)
# Allow table alignment
whitelist[:attributes]['th'] = %w(style)
whitelist[:attributes]['td'] = %w(style)
 
# Allow span elements
whitelist[:elements].push('span')
# Allow span elements
whitelist[:elements].push('span')
 
# Remove `rel` attribute from `a` elements
whitelist[:transformers].push(remove_rel)
# Remove `rel` attribute from `a` elements
whitelist[:transformers].push(remove_rel)
 
# Remove `class` attribute from non-highlight spans
whitelist[:transformers].push(clean_spans)
# Remove `class` attribute from non-highlight spans
whitelist[:transformers].push(clean_spans)
end
 
whitelist
end
 
private
def remove_rel
lambda do |env|
if env[:node_name] == 'a'
Loading
Loading
@@ -48,6 +53,10 @@ module Gitlab
end
end
end
def customized?(transformers)
transformers.last.source_location[0] == __FILE__
end
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment