     }
 
     @inline(__always) private static func parseUserInfoString(userInfoString: String) -> URI.UserInfo? {
-        let userInfoElements = userInfoString.characters.split{$0 == ":"}.map(String.init)
-        return URI.UserInfo(
-            username: userInfoElements[0],
-            password: userInfoElements[1]
-        )
+        let userInfoElements = userInfoString.splitBy(":")
+        if userInfoElements.count == 2 {
+            if let
+                username = String(URLEncodedString: userInfoElements[0]),
+                password = String(URLEncodedString: userInfoElements[1]) {
+                    return URI.UserInfo(
+                        username: username,
+                        password: password
+                    )
+            }
+        }
+
+        return nil
     }
 
     @inline(__always) private static func parseQueryString(queryString: String) -> [String: String] {
         var query: [String: String] = [:]
-        let queryTuples = queryString.characters.split{$0 == "&"}.map(String.init)
+        let queryTuples = queryString.splitBy("&")
         for tuple in queryTuples {
-            let queryElements = tuple.characters.split{$0 == "="}.map(String.init)
+            let queryElements = tuple.splitBy("=")
             if queryElements.count == 1 {
-                query[queryElements[0]] = ""
+                if let name = String(URLEncodedString: queryElements[0]) {
+                    query[name] = ""
+                }
             } else if queryElements.count == 2 {
-                query[queryElements[0]] = queryElements[1]
+                if let
+                    name = String(URLEncodedString: queryElements[0]),
+                    value = String(URLEncodedString: queryElements[1]) {
+                        query[name] = value
+                }
             }
         }
         return query

        let u = parse_uri(string)

        if u.field_set & 1 != 0 {
            scheme = URI.getSubstring(string, start: u.scheme_start, end: u.scheme_end)
        } else {
            scheme = nil
        }

        if u.field_set & 2 != 0 {
            host = URI.getSubstring(string, start: u.host_start, end: u.host_end)
        } else {
            host = nil
        }

        self.host = host
        self.port = port
        self.path = path
        self.query = query
        self.fragment = fragment
    }
}
