AdRoll / goamz

Fork of the GOAMZ version developed within Canonical with additional functionality with DynamoDB
https://wiki.ubuntu.com/goamz
Other
401 stars 214 forks source link

s3 should escape "+" with "%2B" in object key #259

Closed dkolbly closed 9 years ago

dkolbly commented 9 years ago

Attempting to Get() an object whose key includes a "+" character results in a 404 error (if I have List permission on the bucket, that is; otherwise, I get a 403). It looks like partiallyEscapedPath should be escaping "+" with "%2B" but isn't.

I can't find any specific mention of this rule in the AWS documentation except where it talks about request signing (see also issue #243).

Here is a test program:

package main

import (
    "log"
    "fmt"
    "github.com/crowdmob/goamz/aws"
    "github.com/crowdmob/goamz/s3"
)

func AWS() aws.Auth {
    auth, err := aws.EnvAuth()
    if err != nil {
        log.Fatal(err)
    }
    return auth
}

// Region returns the region for use by the aws package
func Region() aws.Region {
    rgn, ok := aws.Regions["us-east-1"]
    if !ok {
        log.Fatal("Unknown region")
    }
    return rgn
}

func main() {
    s3 := s3.New(AWS(), Region())
    b := s3.Bucket("rscheme-docker")
    data, err := b.Get("test/test+plus.now")
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("Data is: %q\n", data)
}

which produces the following output (with s3.go's debug flag set to true):

2014/11/06 14:27:56 Signature payload: "GET\n\n\nThu, 06 Nov 2014 20:27:56 UTC\n/rscheme-docker/test/test+plus.now"
2014/11/06 14:27:56 Signature: "<redacted>"
2014/11/06 14:27:56 Running S3 request: &s3.request{method:"GET", bucket:"rscheme-docker", path:"/rscheme-docker/test/test+plus.now", params:url.Values{}, headers:http.Header{"Host":[]string{"s3.amazonaws.com"}, "Date":[]string{"Thu, 06 Nov 2014 20:27:56 UTC"}, "Authorization":[]string{"AWS <redacted>"}}, baseurl:"https://s3.amazonaws.com", payload:?reflect.Value?, prepared:true}
2014/11/06 14:27:57 } -> HTTP/1.1 404 Not Found
Connection: close
Transfer-Encoding: chunked
Content-Type: application/xml
Date: Thu, 06 Nov 2014 20:27:57 GMT
Server: AmazonS3
X-Amz-Id-2: <redacted>
X-Amz-Request-Id: E886DA21B6EA0191

115
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>test/test plus.now</Key><RequestId>E886DA21B6EA0191</RequestId><HostId>DAO074akQn94Raa/Q4fqCKelHlisazuIXVTCujiFCDgkjPiOvR7SWxBLL2ZQ3FLt</HostId></Error>
0

2014/11/06 14:27:57 got error (status code 404)
2014/11/06 14:27:57     data:
<?xml version="1.0" encoding="UTF-8"?>
<Error><Code>NoSuchKey</Code><Message>The specified key does not exist.</Message><Key>test/test plus.now</Key><RequestId>E886DA21B6EA0191</RequestId><HostId>DAO074akQn94Raa/Q4fqCKelHlisazuIXVTCujiFCDgkjPiOvR7SWxBLL2ZQ3FLt</HostId></Error>

2014/11/06 14:27:57 err: s3.Error{StatusCode:404, Code:"NoSuchKey", Message:"The specified key does not exist.", BucketName:"", RequestId:"E886DA21B6EA0191", HostId:"DAO074akQn94Raa/Q4fqCKelHlisazuIXVTCujiFCDgkjPiOvR7SWxBLL2ZQ3FLt"}
2014/11/06 14:27:57 The specified key does not exist.
dkolbly commented 9 years ago

This is fixed and merged now with PR #260