Skip to content

Commit 0db9e38

Browse files
Merge pull request #17 from FelixHerrmann/dependabot/github_actions/actions/checkout-5
Bump actions/checkout from 4 to 5
2 parents e80fcb3 + 7f30300 commit 0db9e38

7 files changed

Lines changed: 25 additions & 15 deletions

File tree

.github/workflows/swift.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
os: [macos-latest, ubuntu-latest]
1616
runs-on: ${{ matrix.os }}
1717
steps:
18-
- uses: actions/checkout@v4
18+
- uses: actions/checkout@v5
1919
- run: swift build -v
2020

2121
test:
@@ -26,5 +26,5 @@ jobs:
2626
os: [macos-latest, ubuntu-latest]
2727
runs-on: ${{ matrix.os }}
2828
steps:
29-
- uses: actions/checkout@v4
29+
- uses: actions/checkout@v5
3030
- run: swift test -v

.github/workflows/swiftlint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
name: SwiftLint
2323
runs-on: ubuntu-latest
2424
steps:
25-
- uses: actions/checkout@v4
25+
- uses: actions/checkout@v5
2626
- uses: norio-nomura/action-swiftlint@3.2.1
2727
with:
2828
args: --strict

Sources/MultipartFormData/Boundary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,6 @@ extension Boundary: CustomDebugStringConvertible {
104104

105105
extension Boundary {
106106
internal var _value: String {
107-
return String(decoding: _asciiData, as: UTF8.self) // UTF-8 representation is exactly equivalent to ASCII
107+
return String(bytes: _asciiData, encoding: .ascii) ?? ""
108108
}
109109
}

Sources/MultipartFormData/Internal/String+helpers.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
extension String {
99
internal init(_ staticString: StaticString) {
10+
// swiftlint:disable:next optional_data_string_conversion
1011
self = staticString.withUTF8Buffer { String(decoding: $0, as: UTF8.self) }
1112
}
1213
}

Sources/MultipartFormData/MultipartFormData.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ extension MultipartFormData {
162162

163163
extension MultipartFormData: CustomDebugStringConvertible {
164164
public var debugDescription: String {
165-
return String(decoding: contentType._data + ._crlf + ._crlf + httpBody, as: UTF8.self)
165+
let bytes: Data = contentType._data + ._crlf + ._crlf + httpBody
166+
return String(bytes: bytes, encoding: .utf8) ?? ""
166167
}
167168
}

Sources/MultipartFormData/Subpart.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ extension Subpart {
8080

8181
extension Subpart: CustomDebugStringConvertible {
8282
public var debugDescription: String {
83-
return String(decoding: _data, as: UTF8.self)
83+
return String(bytes: _data, encoding: .utf8) ?? ""
8484
}
8585
}
8686

Tests/MultipartFormDataTests/ContentDispositionTests.swift

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,36 @@ import XCTest
99
@testable import MultipartFormData
1010

1111
final class ContentDispositionTests: XCTestCase {
12-
func testPercentEncodingError() throws {
12+
func testUncheckedInitValid() {
1313
XCTAssertNoThrow(try ContentDisposition(uncheckedName: "a", uncheckedFilename: "a"))
14-
14+
}
15+
16+
func testUncheckedInitInvalid() throws {
1517
// https://stackoverflow.com/questions/33558933/why-is-the-return-value-of-string-addingpercentencoding-optional
16-
// does not work on Linux, can still encoding there
17-
let nonPercentEncodableString = try XCTUnwrap(String(bytes: [0xD8, 0x00] as [UInt8], encoding: .utf16BigEndian))
18-
if nonPercentEncodableString.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) == nil {
19-
XCTAssertThrowsError(try ContentDisposition(uncheckedName: nonPercentEncodableString, uncheckedFilename: nil))
20-
XCTAssertThrowsError(try ContentDisposition(uncheckedName: "", uncheckedFilename: nonPercentEncodableString))
18+
let bytes: [UInt8] = [0xD8, 0x00]
19+
20+
// Ensure the non-encodable string can be created, e.g. on iOS 18 it no longer works.
21+
guard let nonPercentEncodableString = String(bytes: bytes, encoding: .utf16BigEndian) else {
22+
throw XCTSkip("UTF16 byte encoding failed")
2123
}
24+
25+
// Ensure the percent-encoding fails on the current platform, e.g. on Linux it encodes.
26+
guard nonPercentEncodableString.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) == nil else {
27+
throw XCTSkip("percent encoding didn't fail")
28+
}
29+
30+
XCTAssertThrowsError(try ContentDisposition(uncheckedName: nonPercentEncodableString, uncheckedFilename: nil))
31+
XCTAssertThrowsError(try ContentDisposition(uncheckedName: "", uncheckedFilename: nonPercentEncodableString))
2232
}
2333

2434
func testParameters() throws {
2535
let contentDisposition = ContentDisposition(name: "a", filename: "a")
26-
2736
XCTAssertEqual(contentDisposition.parameters[0], HTTPHeaderParameter("name", value: "a"))
2837
XCTAssertEqual(contentDisposition.parameters[1], HTTPHeaderParameter("filename", value: "a"))
2938
}
3039

3140
func testData() throws {
3241
let contentDisposition = ContentDisposition(name: "a", filename: "a")
33-
3442
XCTAssertEqual(contentDisposition._data, Data("Content-Disposition: form-data; name=\"a\"; filename=\"a\"".utf8))
3543
}
3644
}

0 commit comments

Comments
 (0)