-
Notifications
You must be signed in to change notification settings - Fork 72
Closed
Labels
Description
Hello,
I have noticed a difference in behavior between the copy constructor and the copy assignment operator in the uri class. This is the code I used:
#include <iostream>
#include <string>
#include "network/uri.hpp"
using network::uri;
void PrintParts(const uri &u) {
std::cout << "scheme : " << u.scheme() << std::endl;
std::cout << "user_info : " << u.user_info() << std::endl;
std::cout << "host : " << u.host() << std::endl;
std::cout << "port : " << u.port() << std::endl;
std::cout << "path : " << u.path() << std::endl;
std::cout << "query : " << u.query() << std::endl;
std::cout << "fragment : " << u.fragment() << std::endl;
}
int main(int argc, char *argv[])
try {
// Using copy constructor
uri u1 = uri(argv[1]);
PrintParts(u1);
std::cout << "==============================" << std::endl;
// Using copy assignment
uri u2;
u2 = uri(argv[1]);
PrintParts(u2);
return 0;
} catch (std::exception &e) {
std::cerr << "error: " << e.what() << std::endl;
return 1;
}Then, when I run it with a URI beginning with file://, I get the following result:
$ ./test file:///path/to/file.txt
scheme : file
user_info :
host :
port :
path : /path/to/file.txt
query :
fragment :
==============================
scheme : file
user_info :
host :
port :
path : path/to/file.txt
query :
fragment :
Notice that the copy assignment operator suppresses the leading forward slash in the path. Pull request #93 doesn't seem to solve this problem.