c++libcurllinefeedcurlpp

Issue with the line feed character in libcurl (curlpp)


I'm currently using curlpp to perform an HTTP query, but curlpp is reporting that there are illegal characters in the URL. I've narrowed down the URL problem to a variable that is being read from a config file (one line, it just contains the information needed). Another weird thing is that this only happens on a Fedora x64bits installation (I haven't tried other x64bits distros). On my two development machines it runs perfectly fine (Ubuntu and OpenSuse, 32bits). I've tried printing the ASCII code of the characters read from the file and everything looks perfectly normal, however, there is a line feed character at the end of the string. Now, this character occurs in all systems, but on the Fedora system it is reported as an illegal character. Replacing this character by the null termination character makes the program work perfectly again.

I was wondering if there is an option to force curlpp to ignore the line feed character. I’ve also tried escaping the string with the curl_easy_escape function, but it converts the line feed character to the percent encoding %0A. This, in turn, is not recognized by the HTTP server as an existing URL (it outputs a 404 error).

Has anyone encountered this issue before? Is it possible to ignore this character, or is the best approach just to replace it?

Thanks in advance for your help!

Best regards,

PS: In all systems, the library versions are the same (which is somewhat weird). The version of curlpp is (0.7.3)

EDIT: Due to popular demand, I'm posting the code that reads the variable from the file.

  std::ifstream keyfile (pathToFile.c_str());
  std::stringstream buffer;
  buffer << keyfile.rdbuf ();

Solution

  • The way you read the key file is going to dump everything into your std::stringstream including the end of line character.

    One thing you can do is use >> which will read the first whole word it finds skipping leading spaces:

    std::ifstream keyfile(pathToFile.c_str());
    std::string api_key;
    
    // will skip leading spaces and only read up to the next space
    // or end of line
    keyfile >> api_key;