File: util.rb

package info (click to toggle)
ruby-aws-sdk-core 3.212.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,232 kB
  • sloc: ruby: 17,533; makefile: 4
file content (29 lines) | stat: -rw-r--r-- 720 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

require 'cgi'

module Seahorse
  # @api private
  module Util
    class << self
      def uri_escape(string)
        CGI.escape(string.to_s.encode('UTF-8')).gsub('+', '%20').gsub('%7E', '~')
      end

      def uri_path_escape(path)
        path.gsub(/[^\/]+/) { |part| uri_escape(part) }
      end

      def escape_header_list_string(s)
        s.include?('"') || s.include?(',') ? "\"#{s.gsub('"', '\"')}\"" : s
      end

      # Checks for a valid host label
      # @see https://tools.ietf.org/html/rfc3986#section-3.2.2
      # @see https://tools.ietf.org/html/rfc1123#page-13
      def host_label?(str)
        str =~ /^(?!-)[a-zA-Z0-9-]{1,63}(?<!-)$/
      end
    end
  end
end