Skip to content

CONFIG: Allow Data URI src for images

Jeremy Baker edited this page Jun 20, 2015 · 3 revisions

In order to support Data URIs, just add the protocol to the config. For example:

# Create a customized copy of the Relaxed config, adding data to the
# existing whitelisted protocols.
Sanitize.fragment(html, Sanitize::Config.merge(Sanitize::Config::RELAXED,
  :protocols => { 
    'img' => { 'src' => ['http', 'https', 'data', :relative] } 
  }
))

NOTE: The use of string keys (instead of symbols img:) is critical for the merge to apply properly.