FIX: Remove double quotes from etag value in API response

FIX: Remove double quotes from etag value in API response

Quotes in response etag value · Issue #1134 · aws/aws-sdk-ruby · GitHub

diff --git a/lib/s3_helper.rb b/lib/s3_helper.rb
index 3e7b6c8..34b0d8c 100644
--- a/lib/s3_helper.rb
+++ b/lib/s3_helper.rb
@@ -43,7 +43,7 @@ class S3Helper
       end
     end
 
-    return path, etag
+    return path, etag.gsub('"', '')
   end
 
   def remove(s3_filename, copy_to_tombstone = false)
diff --git a/spec/components/file_store/s3_store_spec.rb b/spec/components/file_store/s3_store_spec.rb
index e18a092..5364eb4 100644
--- a/spec/components/file_store/s3_store_spec.rb
+++ b/spec/components/file_store/s3_store_spec.rb
@@ -38,18 +38,20 @@ describe FileStore::S3Store do
   context 'uploading to s3' do
     include_context "s3 helpers"
 
+    let(:s3_object) { stub }
     let(:etag) { "etag" }
 
+    before do
+      s3_object.stubs(:put).returns(Aws::S3::Types::PutObjectOutput.new(etag: "\"#{etag}\""))
+    end
+
     describe "#store_upload" do
       it "returns an absolute schemaless url" do
         store.expects(:get_depth_for).with(upload.id).returns(0)
         s3_helper.expects(:s3_bucket).returns(s3_bucket).at_least_once
-        s3_object = stub
 
         s3_bucket.expects(:object).with("original/1X/#{upload.sha1}.png").returns(s3_object)
 
-        s3_object.stubs(:put).returns(Aws::S3::Types::PutObjectOutput.new(etag: etag))
-
         expect(store.store_upload(uploaded_file, upload)).to eq(
           "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/original/1X/#{upload.sha1}.png"
         )
@@ -64,12 +66,9 @@ describe FileStore::S3Store do
         it "returns an absolute schemaless url" do
           store.expects(:get_depth_for).with(upload.id).returns(0)
           s3_helper.expects(:s3_bucket).returns(s3_bucket)
-          s3_object = stub
 
           s3_bucket.expects(:object).with("discourse-uploads/original/1X/#{upload.sha1}.png").returns(s3_object)
 
-          s3_object.stubs(:put).returns(Aws::S3::Types::PutObjectOutput.new(etag: etag))
-
           expect(store.store_upload(uploaded_file, upload)).to eq(
             "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/discourse-uploads/original/1X/#{upload.sha1}.png"
           )
@@ -82,13 +81,10 @@ describe FileStore::S3Store do
       it "returns an absolute schemaless url" do
         store.expects(:get_depth_for).with(optimized_image.upload.id).returns(0)
         s3_helper.expects(:s3_bucket).returns(s3_bucket)
-        s3_object = stub
         path = "optimized/1X/#{optimized_image.upload.sha1}_#{OptimizedImage::VERSION}_100x200.png"
 
         s3_bucket.expects(:object).with(path).returns(s3_object)
 
-        s3_object.stubs(:put).returns(Aws::S3::Types::PutObjectOutput.new(etag: etag))
-
         expect(store.store_optimized_image(optimized_image_file, optimized_image)).to eq(
           "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/#{path}"
         )
@@ -103,13 +99,10 @@ describe FileStore::S3Store do
         it "returns an absolute schemaless url" do
           store.expects(:get_depth_for).with(optimized_image.upload.id).returns(0)
           s3_helper.expects(:s3_bucket).returns(s3_bucket)
-          s3_object = stub
           path = "discourse-uploads/optimized/1X/#{optimized_image.upload.sha1}_#{OptimizedImage::VERSION}_100x200.png"
 
           s3_bucket.expects(:object).with(path).returns(s3_object)
 
-          s3_object.stubs(:put).returns(Aws::S3::Types::PutObjectOutput.new(etag: etag))
-
           expect(store.store_optimized_image(optimized_image_file, optimized_image)).to eq(
             "//s3-upload-bucket.s3.dualstack.us-west-1.amazonaws.com/#{path}"
           )

GitHub sha: cc496de1

1 Like

I wonder who thought this was a good idea to include double quotes in that value…

1 Like