diff --git a/CHANGELOG.md b/CHANGELOG.md index 6e76dbd..bf6174e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## [Unreleased] +- Fix typo in class name `AzureBlob::ForbidenError` to `AzureBlob::ForbiddenError` +- Fix proper URI encoding for keys with special characters like question marks + ## [0.5.8] 2025-05-14 - Add support for copying blobs across containers (#24) diff --git a/lib/azure_blob/client.rb b/lib/azure_blob/client.rb index 3f35c9a..9d1b7f2 100644 --- a/lib/azure_blob/client.rb +++ b/lib/azure_blob/client.rb @@ -194,7 +194,8 @@ def blob_exist?(key, options = {}) # # Returns a hash of the blob's tags. def get_blob_tags(key) - uri = generate_uri("#{container}/#{key}?comp=tags") + uri = generate_uri("#{container}/#{key}") + uri.query = URI.encode_www_form(comp: "tags") response = Http.new(uri, signer:).get Tags.from_response(response).to_h @@ -246,7 +247,8 @@ def delete_container(options = {}) # # Example: +generate_uri("#{container}/#{key}")+ def generate_uri(path) - URI.parse(URI::RFC2396_PARSER.escape(File.join(host, path))) + encoded = path.split("/").map { |segment| CGI.escape(segment) }.join("/") + URI.parse([ host.chomp("/"), encoded ].join("/")) end # Returns an SAS signed URI diff --git a/test/client/test_client.rb b/test/client/test_client.rb index 86c1008..b5b3e10 100644 --- a/test/client/test_client.rb +++ b/test/client/test_client.rb @@ -22,7 +22,8 @@ def setup principal_id: @principal_id, host: @host, ) - @key = "test client##{name}" + @uid = SecureRandom.uuid + @key = "test-client-?-#{name}-#{@uid}" # ? in key to test proper escaping @content = "Some random content #{Random.rand(200)}" end @@ -197,9 +198,9 @@ def test_delete end def test_delete_prefix - prefix = "#{name}_prefix" + prefix = "#{name}_prefix_#{@uid}" keys = 4.times.map do |i| - key = "#{prefix}/#{name}_#{i}" + key = "#{prefix}/#{i}" client.create_block_blob(key, content) key end @@ -212,7 +213,7 @@ def test_delete_prefix end def test_list_prefix - prefix = "#{name}_prefix" + prefix = "#{name}_prefix_#{@uid}" @key = "#{prefix}/#{key}" client.create_block_blob(key, content) @@ -222,9 +223,9 @@ def test_list_prefix end def test_list_blobs_with_pages - prefix = "#{name}_prefix" + prefix = "#{name}_prefix_#{@uid}" keys = 4.times.map do |i| - key = "#{prefix}/#{name}_#{i}" + key = "#{prefix}/#{i}" client.create_block_blob(key, content) key end