File: uri.rb

package info (click to toggle)
ruby-carrierwave 1.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,692 kB
  • sloc: ruby: 9,881; sh: 26; makefile: 5
file content (23 lines) | stat: -rw-r--r-- 501 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
require 'uri'

module CarrierWave
  module Utilities
    module Uri
    # based on Ruby < 2.0's URI.encode
    SAFE_STRING = URI::REGEXP::PATTERN::UNRESERVED + '\/'
    UNSAFE = Regexp.new("[^#{SAFE_STRING}]", false)

    private
      def encode_path(path)
        path.to_s.gsub(UNSAFE) do
          us = $&
          tmp = ''
          us.each_byte do |uc|
            tmp << sprintf('%%%02X', uc)
          end
          tmp
        end
      end
    end # Uri
  end # Utilities
end # CarrierWave