Created
August 17, 2017 12:54
-
-
Save texpert/9535374cbf32ca6da9c52c20de267b37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_support' | |
require 'active_support/all' | |
require 'action_view' | |
array = ['a', 'b', 'http://www.example.com/?a=1', 'is a > 0 & a < 10?'] | |
s = array.join(&:html_safe) | |
safe = array.join(''.html_safe + '').html_safe | |
safe_doubt = array.join(''.html_safe + '') | |
safe_sb = ActiveSupport::SafeBuffer.new(array.join) | |
# Only the next 2 methods are actually sanitizing the string and marking it as `html_safe` | |
include ActionView::Helpers | |
safe_sanitized = sanitize(array.join) | |
include ERB::Util | |
safe_h = h(array.join) | |
puts "s = #{s} is a SafeBuffer? #{s.is_a?(ActiveSupport::SafeBuffer)} Is html_safe? #{s.html_safe?}" | |
puts "safe = #{safe} is a SafeBuffer? #{safe.is_a?(ActiveSupport::SafeBuffer)} Is html_safe? #{safe.html_safe?}" | |
puts "safe_doubt = #{safe_doubt} is a SafeBuffer?"\ | |
" #{safe_doubt.is_a?(ActiveSupport::SafeBuffer)} Is html_safe? #{safe_doubt.html_safe?}" | |
puts "safe_sb = #{safe_sb} is a SafeBuffer?"\ | |
" #{safe_sb.is_a?(ActiveSupport::SafeBuffer)} Is html_safe? #{safe_sb.html_safe?}\n\n" | |
puts "safe_sanitized = #{safe_sanitized} is a SafeBuffer?"\ | |
" #{safe_sanitized.is_a?(ActiveSupport::SafeBuffer)} Is html_safe? #{safe_sanitized.html_safe?}" | |
puts "safe_h = #{safe_h} is a SafeBuffer?"\ | |
" #{safe_h.is_a?(ActiveSupport::SafeBuffer)} Is html_safe? #{safe_h.html_safe?}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment