Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade uri module based on carrierwave 3 #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions lib/carrierwave/utilities/uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@
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)
# based on Ruby < 2.0's URI.encode
PATH_SAFE = URI::REGEXP::PATTERN::UNRESERVED + '\/'
PATH_UNSAFE = Regexp.new("[^#{PATH_SAFE}]", false)
NON_ASCII = /[^[:ascii:]]/.freeze

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
URI::DEFAULT_PARSER.escape(path, PATH_UNSAFE)
end

def encode_non_ascii(str)
URI::DEFAULT_PARSER.escape(str, NON_ASCII)
end

def decode_uri(str)
URI::DEFAULT_PARSER.unescape(str)
end
end # Uri
end # Utilities
end # CarrierWave
end # CarrierWave