Skip to content

Commit

Permalink
Issue #64: removed percent encoding on slugs and parameter values (#65)
Browse files Browse the repository at this point in the history
* removed percent encoding on slugs and parameter values

* code review

* instruct CI to checkout version 3 branch
  • Loading branch information
valeriomazzeo authored and tanner0101 committed Feb 22, 2019
1 parent 3219e32 commit 626190d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/Routing/Routing/TrieRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public final class TrieRouter<Output> {
// a dynamic parameter child was found, we can use it
let value = ParameterValue(
slug: String(data: parameter.value, encoding: .utf8) ?? "",
value: path.routerParameterValue
value: path.routerParameterValue.removingPercentEncoding ?? ""
)
parameters.values.append(value)
currentNode = parameter
Expand Down
23 changes: 22 additions & 1 deletion Tests/RoutingTests/RouterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,27 @@ class RouterTests: XCTestCase {
XCTAssertEqual(router.route(path: ["foo", "bar", "baz", "Tanner"], parameters: &params), 42)
try XCTAssertEqual(params.next(User.self, on: container).wait().name, "Tanner")
}


func testPercentEncodedRouting() throws {
let route = Route(path: ["foo", "bar", "baz", User.parameter], output: 42)
let router = TrieRouter(Int.self)
router.register(route: route)

let container = BasicContainer(
config: Config(),
environment: .development,
services: Services(),
on: EmbeddedEventLoop()
)
var params = Parameters()
XCTAssertEqual(router.route(path: ["foo", "bar", "baz", "abc|1234"], parameters: &params), 42)
try XCTAssertEqual(params.next(User.self, on: container).wait().name, "abc|1234")

var otherParams = Parameters()
XCTAssertEqual(router.route(path: ["foo", "bar", "baz", "abc%7C1234"], parameters: &otherParams), 42)
try XCTAssertEqual(otherParams.next(User.self, on: container).wait().name, "abc|1234")
}

func testCaseSensitiveRouting() throws {
let route = Route<Int>(path: [.constant("path"), .constant("TO"), .constant("fOo")], output: 42)
let router = TrieRouter<Int>()
Expand Down Expand Up @@ -122,6 +142,7 @@ class RouterTests: XCTestCase {

static let allTests = [
("testRouter", testRouter),
("testPercentEncodedRouting", testPercentEncodedRouting),
("testCaseInsensitiveRouting", testCaseInsensitiveRouting),
("testCaseSensitiveRouting", testCaseSensitiveRouting),
("testAnyRouting", testAnyRouting),
Expand Down
2 changes: 1 addition & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
steps:
- run:
name: Clone Vapor
command: git clone -b master https://github.com/vapor/vapor.git
command: git clone -b 3 https://github.com/vapor/vapor.git
working_directory: ~/
- run:
name: Switch Vapor to this Routing revision
Expand Down

0 comments on commit 626190d

Please sign in to comment.