Bugfix: url-encoded chars on the website listener

This commit is contained in:
m-martin-78
2026-08-19 13:54:34 +02:00
parent b2eaf7e795
commit a40aae87c4
4 changed files with 251 additions and 10 deletions
+52
View File
@@ -862,3 +862,55 @@ func WebsiteHosting_options_preflight_missing_origin(s *S3Conf) error {
return checkWebsiteErrorResponse(resp, s3err.GetAPIError(s3err.ErrMissingCORSOrigin))
})
}
// WebsiteHosting_url_encoded_object_key tests that object keys containing
// characters requiring percent-encoding are served, and that a key holding a
// literal percent sign is not decoded twice.
func WebsiteHosting_url_encoded_object_key(s *S3Conf) error {
testName := "WebsiteHosting_url_encoded_object_key"
return actionHandler(s, testName, func(s3client *s3.Client, bucket string) error {
err := putBucketWebsiteConfig(s3client, bucket, &types.WebsiteConfiguration{
IndexDocument: &types.IndexDocument{
Suffix: getPtr("index.html"),
},
})
if err != nil {
return err
}
if err := grantPublicBucketPolicy(s3client, bucket, policyTypeObject); err != nil {
return err
}
for _, test := range []struct {
key string
path string
}{
{"my file.html", "/my%20file.html"},
{"my dir/index.html", "/my%20dir/"},
{"café.html", "/caf%C3%A9.html"},
{"a%20b.html", "/a%2520b.html"},
} {
content := "<html><body>" + test.key + "</body></html>"
_, err = putObjectWithData(int64(len(content)), &s3.PutObjectInput{
Bucket: &bucket,
Key: &test.key,
Body: strings.NewReader(content),
ContentType: getPtr("text/html"),
}, s3client)
if err != nil {
return err
}
resp, err := websiteGet(s, bucket, test.path, nil)
if err != nil {
return err
}
if err := checkWebsiteResponse(resp, http.StatusOK, []byte(content)); err != nil {
return fmt.Errorf("%s: %w", test.path, err)
}
}
return nil
})
}
+2
View File
@@ -717,6 +717,7 @@ func TestWebsiteHosting(ts *TestState) {
ts.Run(WebsiteHosting_options_preflight_access_granted)
ts.Run(WebsiteHosting_options_preflight_access_forbidden)
ts.Run(WebsiteHosting_options_preflight_missing_origin)
ts.Run(WebsiteHosting_url_encoded_object_key)
}
func TestPreflightOPTIONSEndpoint(ts *TestState) {
@@ -1892,6 +1893,7 @@ func GetIntTests() IntTests {
"WebsiteHosting_options_preflight_access_granted": WebsiteHosting_options_preflight_access_granted,
"WebsiteHosting_options_preflight_access_forbidden": WebsiteHosting_options_preflight_access_forbidden,
"WebsiteHosting_options_preflight_missing_origin": WebsiteHosting_options_preflight_missing_origin,
"WebsiteHosting_url_encoded_object_key": WebsiteHosting_url_encoded_object_key,
"PreflightOPTIONS_non_existing_bucket": PreflightOPTIONS_non_existing_bucket,
"PreflightOPTIONS_missing_origin": PreflightOPTIONS_missing_origin,
"PreflightOPTIONS_invalid_request_method": PreflightOPTIONS_invalid_request_method,