Merge pull request #8845 from cole-h/fix-double-percent-encoding

libutil: fix double-encoding of URLs
This commit is contained in:
Eelco Dolstra 2023-08-18 17:08:03 +02:00 committed by GitHub
commit 735558bea6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View file

@ -0,0 +1,22 @@
#include <gtest/gtest.h>
#include "flake/flakeref.hh"
namespace nix {
/* ----------- tests for flake/flakeref.hh --------------------------------------------------*/
/* ----------------------------------------------------------------------------
* to_string
* --------------------------------------------------------------------------*/
TEST(to_string, doesntReencodeUrl) {
auto s = "http://localhost:8181/test/+3d.tar.gz";
auto flakeref = parseFlakeRef(s);
auto parsed = flakeref.to_string();
auto expected = "http://localhost:8181/test/%2B3d.tar.gz";
ASSERT_EQ(parsed, expected);
}
}

View file

@ -44,7 +44,7 @@ ParsedURL parseURL(const std::string & url)
.base = base, .base = base,
.scheme = scheme, .scheme = scheme,
.authority = authority, .authority = authority,
.path = path, .path = percentDecode(path),
.query = decodeQuery(query), .query = decodeQuery(query),
.fragment = percentDecode(std::string(fragment)) .fragment = percentDecode(std::string(fragment))
}; };