summaryrefslogtreecommitdiff
path: root/lib/gitlab/sanitizers/exception_message.rb
blob: 11c91093d88001266d597608a41829111ccae7e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# frozen_string_literal: true

module Gitlab
  module Sanitizers
    module ExceptionMessage
      FILTERED_STRING = '[FILTERED]'
      EXCEPTION_NAMES = %w(URI::InvalidURIError Addressable::URI::InvalidURIError).freeze
      MESSAGE_REGEX = %r{(\A[^:]+:\s).*\Z}.freeze

      class << self
        def clean(exception_name, message)
          return message unless exception_name.in?(EXCEPTION_NAMES)

          message.sub(MESSAGE_REGEX, '\1' + FILTERED_STRING)
        end
      end
    end
  end
end