Class: StringTools::Sanitizer::IframeNormalizer

Inherits:
Object
  • Object
show all
Defined in:
lib/string_tools.rb

Constant Summary collapse

HOSTING_REG =
%r{
  ^https?:\/\/(www\.)?(?:(rutube\.ru\/(video|play|embed))|
  (youtu((?:be|\.be|be\-nocookie)(?:\/|\.com\/(watch|shorts|embed)))|
  ((vkvideo|vk)\.(ru|com)\/video_ext\.php)
  ))
}x.freeze

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ IframeNormalizer

Returns a new instance of IframeNormalizer.



236
237
238
# File 'lib/string_tools.rb', line 236

def initialize(attributes)
  @attributes = attributes
end

Instance Method Details

#call(env) ⇒ Object



240
241
242
243
244
245
246
247
248
249
250
251
# File 'lib/string_tools.rb', line 240

def call(env)
  node = env[:node]

  return unless node.name == 'iframe'

  unless node[:src] =~ HOSTING_REG
    node.unlink
    return
  end

  Sanitize.node!(env[:node], elements: %w(iframe), attributes: {'iframe' => @attributes})
end