Ruby on rails 为什么Rails消毒剂会删除包含大写URL的HREF?
例如:Ruby on rails 为什么Rails消毒剂会删除包含大写URL的HREF?,ruby-on-rails,sanitization,Ruby On Rails,Sanitization,例如: [Dev]> ActionController::Base.helpers.sanitize('<a href="http://google.com">test</a>') => '<a href="http://google.com">test</a>' [Dev]> ActionController::Base.helpers.sanitize('<a href="Http://google.com"&g
[Dev]> ActionController::Base.helpers.sanitize('<a href="http://google.com">test</a>')
=> '<a href="http://google.com">test</a>'
[Dev]> ActionController::Base.helpers.sanitize('<a href="Http://google.com">test</a>')
=> '<a>test</a>'
[Dev]>ActionController::Base.helpers.sanitize(“”)
=> ''
[Dev]>ActionController::Base.helpers.sanitize(“”)
=>“测试”
非常令人沮丧 这似乎是方法
中的一个错误,该方法包含\u坏的\u协议?
正在运行\u controller/vendor/html scanner/html/sanitizer.rb。该方法定义为:
def contains_bad_protocols?(attr_name, value)
uri_attributes.include?(attr_name) &&
(value =~ /(^[^\/:]*):|(�*58)|(p)|(%|%)3A/
&& !allowed_protocols.include?(value.split(protocol_separator).first))
end
和允许的_协议如下:
self.allowed_protocols = Set.new(%w(ed2k ftp http https irc mailto news gopher nntp
telnet webcal xmpp callto feed svn urn aim rsync tag ssh sftp rtsp afs))
因此:
我可以确认我在这里得到了相同的结果3.0.1。恐怕我甚至在rails API中找不到这个函数的文档:(。也许我的搜索技能已经生锈了。
allowed_protocols.include? 'http' => true
allowed_protocols.include? 'Http' => false