Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.

Commit 77e2e58

Browse files
authored
Fix crash on unexpected plugin slugs (#767)
2 parents e173408 + 7d52ac9 commit 77e2e58

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ _None._
4242

4343
### Bug Fixes
4444

45-
_None._
45+
- Fix crash when querying a WordPress plugin whose slug is not url-safe. [#767]
4646

4747
### Internal Changes
4848

Sources/WordPressKit/Services/PluginDirectoryServiceRemote.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public struct PluginDirectoryGetInformationEndpoint {
5858

5959
func buildRequest() throws -> URLRequest {
6060
try HTTPRequestBuilder(url: PluginDirectoryRemoteConstants.getInformationEndpoint)
61-
.append(percentEncodedPath: "\(slug).json")
61+
.appendURLString("\(slug).json")
6262
.query(name: "fields", value: "icons,banners")
6363
.build()
6464
}

Tests/WordPressKitTests/Tests/PluginDirectoryTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,16 @@ class PluginDirectoryTests: XCTestCase {
343343

344344
XCTAssertTrue(lhs == rhs)
345345
}
346+
347+
func testUnconventionalPluginSlug() async throws {
348+
let data = try MockPluginDirectoryProvider.getPluginDirectoryMockData(with: "plugin-directory-rename-xml-rpc", sender: type(of: self))
349+
stub(condition: isHost("api.wordpress.org")) { _ in
350+
HTTPStubsResponse(data: data, statusCode: 200, headers: ["Content-Type": "application/json"])
351+
}
352+
353+
let _ = try await PluginDirectoryServiceRemote().getPluginInformation(slug: "%-is-not-allowed")
354+
let _ = try await PluginDirectoryServiceRemote().getPluginInformation(slug: "中文")
355+
356+
// No assertion needed.
357+
}
346358
}

0 commit comments

Comments
 (0)