Skip to content

Commit

Permalink
Remove chars "@()" from s3PathAllowedCharacters (#604)
Browse files Browse the repository at this point in the history
* Remove chars "@()" from s3PathAllowedCharacters

Some non AWS S3 systems do not cope with non percent encoded version of these characters

* Update s3 allowed characters
To include all characters that might require special handling

* More characters
  • Loading branch information
adam-fowler authored Jun 17, 2022
1 parent d0dada6 commit 9d356c0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Sources/Soto/Extensions/S3/S3RequestMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ public struct S3RequestMiddleware: AWSServiceMiddleware {
}
}

static let pathAllowedCharacters = CharacterSet.urlPathAllowed.subtracting(.init(charactersIn: "+"))
static let s3PathAllowedCharacters = CharacterSet.urlPathAllowed.subtracting(.init(charactersIn: "+@()&$=:,'!*"))
/// percent encode path value.
private static func urlEncodePath(_ value: String) -> String {
return value.addingPercentEncoding(withAllowedCharacters: Self.pathAllowedCharacters) ?? value
return value.addingPercentEncoding(withAllowedCharacters: Self.s3PathAllowedCharacters) ?? value
}

func createBucketFixup(request: inout AWSRequest) {
Expand Down
7 changes: 7 additions & 0 deletions Tests/SotoTests/Services/S3/S3Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,13 @@ class S3Tests: XCTestCase {
XCTAssertEqual(response.body?.asString(), contents)
XCTAssertNotNil(response.lastModified)
}
.flatMap { _ -> EventLoopFuture<S3.ListObjectsV2Output> in
return Self.s3.listObjectsV2(.init(bucket: name))
}
.map { result in
let contents = result.contents
XCTAssertNotNil(contents?.first(where: { $0.key == filename }))
}
.flatAlways { _ in
return Self.deleteBucket(name: name, s3: Self.s3)
}
Expand Down

0 comments on commit 9d356c0

Please sign in to comment.