Sha256: 5e6484fc1e6b271958116796b30c707f036abd8c5e9978bcfbcce1121033db56

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

# Aruba
module Aruba
  # Api
  module Api
    # Text manipulation
    module Text
      # Unescape text
      #
      # '\n' => "\n"
      # '\e' => "\e"
      # '\033' => "\e"
      # '\"' => '"'
      #
      # @param [#to_s] text
      #   Input
      def unescape_text(text)
        text
          .gsub('\n', "\n")
          .gsub('\"', '"')
          .gsub('\e', "\e")
          .gsub('\033', "\e")
          .gsub('\016', "\016")
          .gsub('\017', "\017")
          .gsub('\t', "\t")
      end

      # Remove ansi characters from text
      #
      # @param [#to_s] text
      #   Input
      def extract_text(text)
        text
          .gsub(/(?:\e|\033)\[\d+(?>(;\d+)*)m/, "")
          .gsub(/\\\[|\\\]/, "")
          .gsub(/\007|\016|\017/, "")
      end

      # Unescape special characters and remove ANSI characters
      #
      # @param [#to_s] text
      #   The text to sanitize
      def sanitize_text(text)
        text = unescape_text(text)
        text = extract_text(text) if aruba.config.remove_ansi_escape_sequences

        text.chomp
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/aruba-2.2.0/lib/aruba/api/text.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/aruba-2.2.0/lib/aruba/api/text.rb
aruba-2.2.0 lib/aruba/api/text.rb
aruba-2.1.0 lib/aruba/api/text.rb
aruba-2.0.1 lib/aruba/api/text.rb