Repository: vapor/vapor
File: Tests/VaporTests/URITests.swift (Swift)

Code before:
        XCTAssertURIComponents(
            scheme: "https",
            userinfo: "user:pass",
            host: "vapor.codes",
            port: 1234,
            path: "/foo",
            query: "bar=baz",
            fragment: "qux",
            generate: "https://user:pass@vapor.codes:1234/foo?bar=baz#qux"
        )

        XCTAssertURIString("wss://echo.websocket.org/", hasScheme: "wss", hasHost: "echo.websocket.org", hasPath: "/")
        XCTAssertURIComponents(scheme: "wss", host: "echo.websocket.org", path: "/", generate: "wss://echo.websocket.org/")
    }
    
    func testSpecialCharacters() {
        XCTAssertURIString(
            "https://user:pass@vapor.codes:1234/foo;?bar=abcd%C3%A4%2B#qux",
            hasScheme: "https",
            hasUserinfo: "user:pass",
            hasHost: "vapor.codes",
            hasPort: 1234,
            hasPath: "/foo;",
            hasQuery: "bar=abcd%C3%A4%2B",
            hasFragment: "qux"
        )
    }
    
    func testMutation() {
        var uri = URI(string: "https://user:pass@vapor.codes:1234/foo?bar=baz#qux")
    
        // Mutate query
        uri.query = "bar=baz&test=1"
        XCTAssertEqual(uri.string, "https://user:pass@vapor.codes:1234/foo?bar=baz&test=1#qux")

        // Remove query
        uri.query = nil
        XCTAssertEqual(uri.string, "https://user:pass@vapor.codes:1234/foo#qux")
    }
    
    func testPathStrings() {
        // Absolute path string
        let uri = URI(string: "/foo/bar/baz")
        XCTAssertEqual(uri.path, "/foo/bar/baz")
    }
    
    func testNonAbsolutePath() {
        let uri = URI(string: "foo")

        // N.B.: This test previously asserted that the _scheme_ of the resulting URI was `foo`. This was
        // a semantically incorrect parse (per RFC 3986) and should have been considered a bug; hence it

Review comment (suggestion):
```suggestion
    func testSemicolonIsNotEncodedInPathComponent() {
        XCTAssertURIString(
            "https://user:pass@vapor.codes:1234/foo;?bar=abcd%3B%C3%A4%2B#qux%3B",
            hasScheme: "https",
            hasUserinfo: "user:pass",
            hasHost: "vapor.codes",
            hasPort: 1234,
            hasPath: "/foo;",
            hasQuery: "bar=abcd%3B%C3%A4%2B",
            hasFragment: "qux%3B"
        )
```
^ so that we test that we're _specifically_ only mutating the path component.

Code after:
        XCTAssertURIComponents(
            scheme: "https",
            userinfo: "user:pass",
            host: "vapor.codes",
            port: 1234,
            path: "/foo",
            query: "bar=baz",
            fragment: "qux",
            generate: "https://user:pass@vapor.codes:1234/foo?bar=baz#qux"
        )

        XCTAssertURIString("wss://echo.websocket.org/", hasScheme: "wss", hasHost: "echo.websocket.org", hasPath: "/")
        XCTAssertURIComponents(scheme: "wss", host: "echo.websocket.org", path: "/", generate: "wss://echo.websocket.org/")
    }
    
    func testSemicolonIsNotEncodedInPathComponent() {
        XCTAssertURIString(
            "https://user:pass@vapor.codes:1234/foo;?bar=abcd%3B%C3%A4%2B;efg#qux%3B",
            hasScheme: "https",
            hasUserinfo: "user:pass",
            hasHost: "vapor.codes",
            hasPort: 1234,
            hasPath: "/foo;",
            hasQuery: "bar=abcd%3B%C3%A4%2B;efg",
            hasFragment: "qux%3B"
        )
    }
    
    func testMutation() {
        var uri = URI(string: "https://user:pass@vapor.codes:1234/foo?bar=baz#qux")
    
        // Mutate query
        uri.query = "bar=baz&test=1"
        XCTAssertEqual(uri.string, "https://user:pass@vapor.codes:1234/foo?bar=baz&test=1#qux")

        // Remove query
        uri.query = nil
        XCTAssertEqual(uri.string, "https://user:pass@vapor.codes:1234/foo#qux")
    }
    
    func testPathStrings() {
        // Absolute path string
        let uri = URI(string: "/foo/bar/baz")
        XCTAssertEqual(uri.path, "/foo/bar/baz")
    }
    
    func testNonAbsolutePath() {
        let uri = URI(string: "foo")

        // N.B.: This test previously asserted that the _scheme_ of the resulting URI was `foo`. This was
        // a semantically incorrect parse (per RFC 3986) and should have been considered a bug; hence it