Sha256: 06707ace71f06760cf52ac7d497dad1c76623debfca68dd1287e780e56e56496

Contents?: true

Size: 1.5 KB

Versions: 8

Compression:

Stored size: 1.5 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Discourse
      # Do not use URI.escape and its ilk, they are deprecated
      # with a warning in the ruby source. Instead use
      # Addressable::URI, which has encode, encode_component,
      # and unencode methods. UrlHelper has helper methods for this.
      #
      # # @example
      #   # bad
      #   URI.encode("https://a%20a.com?a='a%22")
      #
      #   # good
      #   UrlHelper.encode("https://a%20a.com?a='a%22")
      #   Addressable::URI.encode("https://a%20a.com?a='a%22")
      class NoURIEscapeEncode < Base
        MSG =
          "URI.escape, URI.encode, URI.unescape, URI.decode are deprecated and should not be used."

        def_node_matcher :using_uri_escape?, <<-MATCHER
          (send (const nil? :URI) :escape ...)
        MATCHER

        def_node_matcher :using_uri_encode?, <<-MATCHER
          (send (const nil? :URI) :encode ...)
        MATCHER

        def_node_matcher :using_uri_unescape?, <<-MATCHER
          (send (const nil? :URI) :unescape ...)
        MATCHER

        def_node_matcher :using_uri_decode?, <<-MATCHER
          (send (const nil? :URI) :decode ...)
        MATCHER

        def on_send(node)
          if [
               using_uri_escape?(node),
               using_uri_encode?(node),
               using_uri_unescape?(node),
               using_uri_decode?(node),
             ].none?
            return
          end
          add_offense(node, message: MSG)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
rubocop-discourse-3.9.2 lib/rubocop/cop/discourse/no_uri_escape_encode.rb
rubocop-discourse-3.9.1 lib/rubocop/cop/discourse/no_uri_escape_encode.rb
rubocop-discourse-3.9.0 lib/rubocop/cop/discourse/no_uri_escape_encode.rb
rubocop-discourse-3.8.6 lib/rubocop/cop/discourse/no_uri_escape_encode.rb
rubocop-discourse-3.8.5 lib/rubocop/cop/discourse/no_uri_escape_encode.rb
rubocop-discourse-3.8.4 lib/rubocop/cop/discourse/no_uri_escape_encode.rb
rubocop-discourse-3.8.3 lib/rubocop/cop/discourse/no_uri_escape_encode.rb
rubocop-discourse-3.8.2 lib/rubocop/cop/discourse/no_uri_escape_encode.rb