reapack

Package manager for REAPER
Log | Files | Refs | Submodules | README | LICENSE

commit 453b356a7427f23f381b9763108f171d6b42f785
parent afc76fae52a5d9fb0437e15e9aec8d45fa3af359
Author: cfillion <cfillion@users.noreply.github.com>
Date:   Mon,  4 Jan 2016 11:59:40 -0500

validate remote urls

Diffstat:
Msrc/remote.cpp | 11++++++++++-
Mtest/remote.cpp | 24++++++++++++++++++++++--
Rtest/remote/missing_url.ReaPackRemote -> test/remote/invalid_url.ReaPackRemote | 0
3 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/src/remote.cpp b/src/remote.cpp @@ -40,7 +40,16 @@ static bool ValidateName(const string &name) static bool ValidateUrl(const string &url) { - return !url.empty(); + using namespace std::regex_constants; + + // see http://tools.ietf.org/html/rfc3986#section-2 + static const regex pattern( + "^(?:[a-z0-9._~:/?#[\\]@!$&'()*+,;=-]|%[a-f0-9]{2})+$", icase); + + smatch match; + regex_match(url, match, pattern); + + return !match.empty(); } Remote Remote::fromFile(const string &path, ReadCode *code) diff --git a/test/remote.cpp b/test/remote.cpp @@ -48,6 +48,16 @@ TEST_CASE("construct invalid remote", M) { REQUIRE(string(e.what()) == "invalid url"); } } + + SECTION("invalid url") { + try { + Remote remote("name", "hello world"); + FAIL(); + } + catch(const reapack_error &e) { + REQUIRE(string(e.what()) == "invalid url"); + } + } } TEST_CASE("set invalid values", M) { @@ -65,7 +75,7 @@ TEST_CASE("set invalid values", M) { SECTION("url") { try { - remote.setUrl({}); + remote.setUrl("http://google.com/hello?invalid=|"); FAIL(); } catch(const reapack_error &e) { @@ -74,6 +84,16 @@ TEST_CASE("set invalid values", M) { } } +TEST_CASE("valide remote urls", M) { + Remote remote; + + SECTION("uppercase") + remote.setUrl("https://google.com/AAA"); + + SECTION("escape sequence") + remote.setUrl("https://google.com/?q=hello%20world"); +} + TEST_CASE("null remote", M) { Remote remote; REQUIRE(remote.isNull()); @@ -175,7 +195,7 @@ TEST_CASE("remote from file", M) { SECTION("invalid url") { Remote::ReadCode code; const Remote remote = Remote::fromFile( - RPATH "missing_url.ReaPackRemote", &code); + RPATH "invalid_url.ReaPackRemote", &code); REQUIRE(code == Remote::InvalidUrl); REQUIRE_FALSE(remote.isValid()); diff --git a/test/remote/missing_url.ReaPackRemote b/test/remote/invalid_url.ReaPackRemote