sanitize-rails 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sanitize/rails.rb +1 -2
- data/lib/sanitize/rails/engine.rb +31 -24
- data/lib/sanitize/rails/version.rb +1 -1
- data/sanitize-rails.gemspec +1 -2
- data/test/sanitize_rails_engine_test.rb +3 -5
- metadata +1 -15
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: c819bce23ea04e1acd72e959589b2e0a4b509ba8
         | 
| 4 | 
            +
              data.tar.gz: 9b3b305b20a916fa669c63b996a80661bc7fc214
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: bc5faf19b023736f41e095fc87159f10e02a0fb36b0d26040fd57cb48ea106cc10d4d3b93c0fd15a6f05eb6d88dbf3bd7803334035b97ae03d8a865fc7fcf789
         | 
| 7 | 
            +
              data.tar.gz: 0dde098f9ef4b40c5572888862339fba2d9fa932531fed50e838e7b79f0e4149f94805b9c9a06a3b034ecea64068069fecd72b9ad3d4f8638e8216f122a6e353
         | 
    
        data/lib/sanitize/rails.rb
    CHANGED
    
    | @@ -3,12 +3,11 @@ | |
| 3 3 | 
             
            #
         | 
| 4 4 | 
             
            # https://github.com/vjt/sanitize-rails
         | 
| 5 5 | 
             
            #
         | 
| 6 | 
            -
            # (C) 2011- | 
| 6 | 
            +
            # (C) 2011-2015 vjt@openssl.it
         | 
| 7 7 | 
             
            #
         | 
| 8 8 | 
             
            # MIT License
         | 
| 9 9 | 
             
            #
         | 
| 10 10 | 
             
            require 'sanitize'
         | 
| 11 | 
            -
            require 'htmlentities'
         | 
| 12 11 | 
             
            require 'sanitize/rails/railtie' if defined? Rails
         | 
| 13 12 |  | 
| 14 13 | 
             
            module Sanitize::Rails
         | 
| @@ -3,8 +3,36 @@ module Sanitize::Rails | |
| 3 3 | 
             
              module Engine
         | 
| 4 4 | 
             
                extend self
         | 
| 5 5 |  | 
| 6 | 
            +
                # Changes the Sanitizer configuration.
         | 
| 7 | 
            +
                #
         | 
| 6 8 | 
             
                def configure(config)
         | 
| 7 | 
            -
                   | 
| 9 | 
            +
                  @_config = config.freeze
         | 
| 10 | 
            +
                  @_cleaner = nil
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                # Returns the current Sanitizer configuration. The configuration is built
         | 
| 14 | 
            +
                # from Rails configuration, if defined, else Sanitize::Config::BASIC is
         | 
| 15 | 
            +
                # used.
         | 
| 16 | 
            +
                #
         | 
| 17 | 
            +
                # FIXME: Remove this, as it is meant only not to break assumptions on old
         | 
| 18 | 
            +
                # applications.
         | 
| 19 | 
            +
                #
         | 
| 20 | 
            +
                if defined?(::ActionView::Base) &&
         | 
| 21 | 
            +
                  ::ActionView::Base.respond_to?(:sanitized_allowed_tags) &&
         | 
| 22 | 
            +
                  ::ActionView::Base.sanitized_allowed_tags.respond_to?(:size) &&
         | 
| 23 | 
            +
                  ::ActionView::Base.sanitized_allowed_tags.size > 0
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  def config
         | 
| 26 | 
            +
            	@_config ||= {
         | 
| 27 | 
            +
            	  :elements => ::ActionView::Base.sanitized_allowed_tags.to_a,
         | 
| 28 | 
            +
            	  :attributes => { :all => ::ActionView::Base.sanitized_allowed_attributes.to_a },
         | 
| 29 | 
            +
            	  :protocols  => { :all => ::ActionView::Base.sanitized_allowed_protocols.to_a }
         | 
| 30 | 
            +
            	}
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
                else
         | 
| 33 | 
            +
                  def config
         | 
| 34 | 
            +
            	@_config ||= ::Sanitize::Config::BASIC
         | 
| 35 | 
            +
                  end
         | 
| 8 36 | 
             
                end
         | 
| 9 37 |  | 
| 10 38 | 
             
                # Returns a memoized instance of the Engine with the
         | 
| @@ -12,22 +40,7 @@ module Sanitize::Rails | |
| 12 40 | 
             
                # the ActionView's default config
         | 
| 13 41 | 
             
                #
         | 
| 14 42 | 
             
                def cleaner
         | 
| 15 | 
            -
                   | 
| 16 | 
            -
                    {
         | 
| 17 | 
            -
                      :elements   => ::ActionView::Base.sanitized_allowed_tags.to_a,
         | 
| 18 | 
            -
                      :attributes => { :all => ::ActionView::Base.sanitized_allowed_attributes.to_a},
         | 
| 19 | 
            -
                      :protocols  => { :all => ::ActionView::Base.sanitized_allowed_protocols.to_a },
         | 
| 20 | 
            -
                      :escape_entities => true
         | 
| 21 | 
            -
                    }
         | 
| 22 | 
            -
                  rescue
         | 
| 23 | 
            -
                    warn "ActionView not available, falling back to Sanitize's BASIC config"
         | 
| 24 | 
            -
                    ::Sanitize::Config::BASIC
         | 
| 25 | 
            -
                  end
         | 
| 26 | 
            -
                  @sanitizer ||= ::Sanitize.new(@@config)
         | 
| 27 | 
            -
                end
         | 
| 28 | 
            -
             | 
| 29 | 
            -
                def coder
         | 
| 30 | 
            -
                  @coder ||= HTMLEntities.new
         | 
| 43 | 
            +
                  @_cleaner ||= ::Sanitize.new(config)
         | 
| 31 44 | 
             
                end
         | 
| 32 45 |  | 
| 33 46 | 
             
                # Returns a copy of the given `string` after sanitizing it and marking it
         | 
| @@ -63,14 +76,8 @@ module Sanitize::Rails | |
| 63 76 |  | 
| 64 77 | 
             
                private
         | 
| 65 78 |  | 
| 66 | 
            -
                def escape_entities
         | 
| 67 | 
            -
                  @@config[:escape_entities].nil? ? true : @@config[:escape_entities]
         | 
| 68 | 
            -
                end
         | 
| 69 | 
            -
             | 
| 70 79 | 
             
                def cleaned_fragment(string)
         | 
| 71 | 
            -
                   | 
| 72 | 
            -
                  result = coder.decode(result) unless escape_entities
         | 
| 73 | 
            -
                  result
         | 
| 80 | 
            +
                  cleaner.fragment(string)
         | 
| 74 81 | 
             
                end
         | 
| 75 82 | 
             
              end
         | 
| 76 83 | 
             
            end
         | 
    
        data/sanitize-rails.gemspec
    CHANGED
    
    | @@ -17,7 +17,6 @@ Gem::Specification.new do |s| | |
| 17 17 | 
             
              s.require_paths = ["lib"]
         | 
| 18 18 | 
             
              s.files         = `git ls-files`.split("\n")
         | 
| 19 19 |  | 
| 20 | 
            -
              s.add_dependency "rails", | 
| 20 | 
            +
              s.add_dependency "rails",    ">= 3.0"
         | 
| 21 21 | 
             
              s.add_dependency "sanitize", "~> 3.0"
         | 
| 22 | 
            -
              s.add_dependency "htmlentities", "~> 4.3.3"
         | 
| 23 22 | 
             
            end
         | 
| @@ -47,16 +47,14 @@ class SanitizeRailsEngineTest < Minitest::Test | |
| 47 47 | 
             
                assert_instance_of ::ActiveSupport::SafeBuffer, new_string
         | 
| 48 48 | 
             
              end
         | 
| 49 49 |  | 
| 50 | 
            -
              def  | 
| 51 | 
            -
                string = %Q | 
| 52 | 
            -
                @engine.configure(escape_entities: false)
         | 
| 50 | 
            +
              def test_clean_not_producing_malicious_html_entities
         | 
| 51 | 
            +
                string = %Q|<script>hello & world</script>|
         | 
| 53 52 | 
             
                @engine.clean! string
         | 
| 54 | 
            -
                assert_equal string, "hello & world"
         | 
| 53 | 
            +
                assert_equal string, "<script>hello & world</script>"
         | 
| 55 54 | 
             
              end
         | 
| 56 55 |  | 
| 57 56 | 
             
              def test_clean_making_html_entities
         | 
| 58 57 | 
             
                string = %Q|<script>hello & world</script>|
         | 
| 59 | 
            -
                @engine.configure(escape_entities: true)
         | 
| 60 58 | 
             
                @engine.clean! string
         | 
| 61 59 | 
             
                assert_equal string, "hello & world"
         | 
| 62 60 | 
             
              end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: sanitize-rails
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1.0 | 
| 4 | 
            +
              version: 1.1.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Marcello Barnaba
         | 
| @@ -40,20 +40,6 @@ dependencies: | |
| 40 40 | 
             
                - - "~>"
         | 
| 41 41 | 
             
                  - !ruby/object:Gem::Version
         | 
| 42 42 | 
             
                    version: '3.0'
         | 
| 43 | 
            -
            - !ruby/object:Gem::Dependency
         | 
| 44 | 
            -
              name: htmlentities
         | 
| 45 | 
            -
              requirement: !ruby/object:Gem::Requirement
         | 
| 46 | 
            -
                requirements:
         | 
| 47 | 
            -
                - - "~>"
         | 
| 48 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 49 | 
            -
                    version: 4.3.3
         | 
| 50 | 
            -
              type: :runtime
         | 
| 51 | 
            -
              prerelease: false
         | 
| 52 | 
            -
              version_requirements: !ruby/object:Gem::Requirement
         | 
| 53 | 
            -
                requirements:
         | 
| 54 | 
            -
                - - "~>"
         | 
| 55 | 
            -
                  - !ruby/object:Gem::Version
         | 
| 56 | 
            -
                    version: 4.3.3
         | 
| 57 43 | 
             
            description: 
         | 
| 58 44 | 
             
            email:
         | 
| 59 45 | 
             
            - vjt@openssl.it
         |