зеркало из https://github.com/github/aws-s3.git
escape header values
This commit is contained in:
Родитель
412110ac73
Коммит
9b556eac46
|
@ -28,19 +28,30 @@ require 's3/connection'
|
|||
require 's3/authentication'
|
||||
require 's3/response'
|
||||
|
||||
AWS::S3::Base.class_eval do
|
||||
module AWS
|
||||
module S3
|
||||
UNSAFE_URI = /[^-_.!~*'()a-zA-Z\d;\/?:@&=$,\[\]]/n
|
||||
|
||||
def self.escape_uri(path)
|
||||
URI.escape(path.to_s, UNSAFE_URI)
|
||||
end
|
||||
|
||||
Base.class_eval do
|
||||
include AWS::S3::Connection::Management
|
||||
end
|
||||
|
||||
AWS::S3::Bucket.class_eval do
|
||||
Bucket.class_eval do
|
||||
include AWS::S3::Logging::Management
|
||||
include AWS::S3::ACL::Bucket
|
||||
end
|
||||
|
||||
AWS::S3::S3Object.class_eval do
|
||||
S3Object.class_eval do
|
||||
include AWS::S3::ACL::S3Object
|
||||
include AWS::S3::BitTorrent
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
require_library_or_gem 'xmlsimple', 'xml-simple' unless defined? XmlSimple
|
||||
# If libxml is installed, we use the FasterXmlSimple library, that provides most of the functionality of XmlSimple
|
||||
|
|
|
@ -8,7 +8,7 @@ module AWS
|
|||
|
||||
def prepare_path(path)
|
||||
path = path.remove_extended unless path.valid_utf8?
|
||||
URI.escape(path)
|
||||
AWS::S3.escape_uri(path)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ class Hash
|
|||
unless empty?
|
||||
query_string << '?' if include_question_mark
|
||||
query_string << inject([]) do |params, (key, value)|
|
||||
params << "#{key}=#{value}"
|
||||
params << "#{key}=#{AWS::S3.escape_uri(value)}"
|
||||
end.join('&')
|
||||
end
|
||||
query_string
|
||||
|
|
|
@ -27,6 +27,11 @@ class HashExtensionsTest < Test::Unit::TestCase
|
|||
assert qs['one=1&two=2'] || qs['two=2&one=1']
|
||||
end
|
||||
|
||||
def test_escape_values
|
||||
hash = {:one => '5+ 1'}
|
||||
assert_equal '?one=5%2B%201', hash.to_query_string
|
||||
end
|
||||
|
||||
def test_normalized_options
|
||||
expectations = [
|
||||
[{:foo_bar => 1}, {'foo-bar' => '1'}],
|
||||
|
|
Загрузка…
Ссылка в новой задаче