s3store: stricter character replacement regexp for x-amz-metadata (#598)

* stricter character replacement rule for x-amz-metadata

* misspell fixed
This commit is contained in:
Anatoly 2021-12-30 19:17:45 +03:00 committed by GitHub
parent 880c71fa82
commit 6828cbdce1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 6 deletions

View File

@ -92,11 +92,9 @@ import (
"github.com/aws/aws-sdk-go/service/s3" "github.com/aws/aws-sdk-go/service/s3"
) )
// This regular expression matches every character which is not defined in the // This regular expression matches every character which is not
// ASCII tables which range from 00 to 7F, inclusive. // considered valid into a header value according to RFC2616.
// It also matches the \r and \n characters which are not allowed in values var nonPrintableRegexp = regexp.MustCompile(`[^\x09\x20-\x7E]`)
// for HTTP headers.
var nonASCIIRegexp = regexp.MustCompile(`([^\x00-\x7F]|[\r\n])`)
// See the handler.DataStore interface for documentation about the different // See the handler.DataStore interface for documentation about the different
// methods. // methods.
@ -230,7 +228,7 @@ func (store S3Store) NewUpload(ctx context.Context, info handler.FileInfo) (hand
for key, value := range info.MetaData { for key, value := range info.MetaData {
// Copying the value is required in order to prevent it from being // Copying the value is required in order to prevent it from being
// overwritten by the next iteration. // overwritten by the next iteration.
v := nonASCIIRegexp.ReplaceAllString(value, "?") v := nonPrintableRegexp.ReplaceAllString(value, "?")
metadata[key] = &v metadata[key] = &v
} }