diff --git a/config.go b/config.go index e72c6a8..5a7326a 100644 --- a/config.go +++ b/config.go @@ -47,7 +47,7 @@ type Config struct { func (config *Config) validate() error { if config.Logger == nil { - config.Logger = log.New(os.Stdout, "[tusd] ", log.Ldate | log.Ltime) + config.Logger = log.New(os.Stdout, "[tusd] ", log.Ldate|log.Ltime) } base := config.BasePath diff --git a/s3store/s3store.go b/s3store/s3store.go index a6d2c94..8f9d440 100644 --- a/s3store/s3store.go +++ b/s3store/s3store.go @@ -90,7 +90,9 @@ import ( // This regular expression matches every character which is not defined in the // ASCII tables which range from 00 to 7F, inclusive. -var nonASCIIRegexp = regexp.MustCompile(`([^\x00-\x7F])`) +// 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])`) // See the tusd.DataStore interface for documentation about the different // methods. diff --git a/s3store/s3store_test.go b/s3store/s3store_test.go index 463794a..070a079 100644 --- a/s3store/s3store_test.go +++ b/s3store/s3store_test.go @@ -37,7 +37,7 @@ func TestNewUpload(t *testing.T) { assert.Equal(s3obj, store.Service) s1 := "hello" - s2 := "men?" + s2 := "men???hi" gomock.InOrder( s3obj.EXPECT().CreateMultipartUpload(&s3.CreateMultipartUploadInput{ @@ -53,8 +53,8 @@ func TestNewUpload(t *testing.T) { s3obj.EXPECT().PutObject(&s3.PutObjectInput{ Bucket: aws.String("bucket"), Key: aws.String("uploadId.info"), - Body: bytes.NewReader([]byte(`{"ID":"uploadId+multipartId","Size":500,"SizeIsDeferred":false,"Offset":0,"MetaData":{"bar":"menü","foo":"hello"},"IsPartial":false,"IsFinal":false,"PartialUploads":null}`)), - ContentLength: aws.Int64(int64(171)), + Body: bytes.NewReader([]byte(`{"ID":"uploadId+multipartId","Size":500,"SizeIsDeferred":false,"Offset":0,"MetaData":{"bar":"menü\r\nhi","foo":"hello"},"IsPartial":false,"IsFinal":false,"PartialUploads":null}`)), + ContentLength: aws.Int64(int64(177)), }), ) @@ -63,7 +63,7 @@ func TestNewUpload(t *testing.T) { Size: 500, MetaData: map[string]string{ "foo": "hello", - "bar": "menü", + "bar": "menü\r\nhi", }, } @@ -243,8 +243,8 @@ func TestGetInfoWithIncompletePart(t *testing.T) { Bucket: aws.String("bucket"), Key: aws.String("uploadId.part"), }).Return(&s3.GetObjectOutput{ - ContentLength: aws.Int64(10), - Body: ioutil.NopCloser(bytes.NewReader([]byte("0123456789"))), + ContentLength: aws.Int64(10), + Body: ioutil.NopCloser(bytes.NewReader([]byte("0123456789"))), }, nil), ) @@ -730,8 +730,8 @@ func TestWriteChunkPrependsIncompletePart(t *testing.T) { Bucket: aws.String("bucket"), Key: aws.String("uploadId.part"), }).Return(&s3.GetObjectOutput{ - ContentLength: aws.Int64(3), - Body: ioutil.NopCloser(bytes.NewReader([]byte("123"))), + ContentLength: aws.Int64(3), + Body: ioutil.NopCloser(bytes.NewReader([]byte("123"))), }, nil), s3obj.EXPECT().ListParts(&s3.ListPartsInput{ Bucket: aws.String("bucket"),