Skip to content

Commit

Permalink
Add test for percentDecode changes
Browse files Browse the repository at this point in the history
  • Loading branch information
adam-fowler committed Mar 24, 2024
1 parent 64eebea commit 4f040d9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Tests/HummingbirdTests/RouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,30 @@ final class RouterTests: XCTestCase {
XCTAssertEqual(response.status, .seeOther)
}
}

/// Test the hummingbird core parser against possible overflows of the percent encoder. this issue was introduced in pr #404 in the context of query parameters but I've thrown in some other random overflow scenarios in here too for good measure. if it doesn't crash, its a win.
func testQueryParameterOverflow() throws {
let app = HBApplication(testing: .embedded)
app.router.get("overflow") { req in
let currentQP = req.uri.queryParameters["query"]
return String("\(currentQP ?? "")")
}
try app.XCTStart()
defer { app.XCTStop() }

try app.XCTExecute(uri: "/overflow?query=value%", method: .GET) { response in
let body = try XCTUnwrap(response.body)
XCTAssertEqual(String(buffer: body), "value%")
}
try app.XCTExecute(uri: "/overflow?query%=value%", method: .GET) { response in
let body = try XCTUnwrap(response.body)
XCTAssertEqual(String(buffer: body), "")
}
try app.XCTExecute(uri: "/overflow?%&", method: .GET) { response in
let body = try XCTUnwrap(response.body)
XCTAssertEqual(String(buffer: body), "")
}
}
}

extension HBRequest {
Expand Down

0 comments on commit 4f040d9

Please sign in to comment.