File tree 2 files changed +8
-3
lines changed
2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -42,9 +42,7 @@ const (
42
42
func encodeURL2Path (u * url.URL ) (path string ) {
43
43
// Encode URL path.
44
44
if isS3 , _ := filepath .Match ("*.s3*.amazonaws.com" , u .Host ); isS3 {
45
- hostSplits := strings .SplitN (u .Host , "." , 4 )
46
- // First element is the bucket name.
47
- bucketName := hostSplits [0 ]
45
+ bucketName := u .Host [:strings .LastIndex (u .Host , ".s3" )]
48
46
path = "/" + bucketName
49
47
path += u .Path
50
48
path = s3utils .EncodePath (path )
Original file line number Diff line number Diff line change @@ -25,29 +25,35 @@ import (
25
25
// Tests url encoding.
26
26
func TestEncodeURL2Path (t * testing.T ) {
27
27
type urlStrings struct {
28
+ bucketName string
28
29
objName string
29
30
encodedObjName string
30
31
}
31
32
32
33
bucketName := "bucketName"
33
34
want := []urlStrings {
34
35
{
36
+ bucketName : "bucketName" ,
35
37
objName : "本語" ,
36
38
encodedObjName : "%E6%9C%AC%E8%AA%9E" ,
37
39
},
38
40
{
41
+ bucketName : "bucketName" ,
39
42
objName : "本語.1" ,
40
43
encodedObjName : "%E6%9C%AC%E8%AA%9E.1" ,
41
44
},
42
45
{
43
46
objName : ">123>3123123" ,
47
+ bucketName : "bucketName" ,
44
48
encodedObjName : "%3E123%3E3123123" ,
45
49
},
46
50
{
51
+ bucketName : "bucketName" ,
47
52
objName : "test 1 2.txt" ,
48
53
encodedObjName : "test%201%202.txt" ,
49
54
},
50
55
{
56
+ bucketName : "test.bucketName" ,
51
57
objName : "test++ 1.txt" ,
52
58
encodedObjName : "test%2B%2B%201.txt" ,
53
59
},
@@ -63,4 +69,5 @@ func TestEncodeURL2Path(t *testing.T) {
63
69
t .Fatal ("Error" )
64
70
}
65
71
}
72
+
66
73
}
You can’t perform that action at this time.
0 commit comments