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