mirror of
https://github.com/OpenVPN/openvpn3.git
synced 2024-09-20 04:02:15 +02:00
In urlencode.hpp decode_path() method, remove leading '/'
from URI. Also added new methods match_path() and match_prefix().
This commit is contained in:
parent
ec2f50fa0f
commit
e19ce0506a
@ -27,6 +27,7 @@
|
||||
|
||||
#include <openvpn/common/exception.hpp>
|
||||
#include <openvpn/common/split.hpp>
|
||||
#include <openvpn/common/string.hpp>
|
||||
#include <openvpn/common/hexstr.hpp>
|
||||
#include <openvpn/common/unicode.hpp>
|
||||
|
||||
@ -84,14 +85,35 @@ namespace openvpn {
|
||||
return ret;
|
||||
}
|
||||
|
||||
inline std::vector<std::string> decode_path(const std::string& path)
|
||||
inline std::vector<std::string> decode_path(std::string path)
|
||||
{
|
||||
std::vector<std::string> list;
|
||||
if (!path.empty() && path[0] == '/')
|
||||
path = path.substr(1);
|
||||
Split::by_char_void<decltype(list), NullLex, Split::NullLimit>(list, path, '/');
|
||||
for (auto &i : list)
|
||||
i = decode(i);
|
||||
return list;
|
||||
}
|
||||
|
||||
inline bool match_path(const std::string& uri, const std::vector<std::string>& choices)
|
||||
{
|
||||
if (uri.empty())
|
||||
return false;
|
||||
if (uri[0] != '/')
|
||||
return false;
|
||||
return std::find(choices.begin(), choices.end(), uri.substr(1)) != choices.end();
|
||||
}
|
||||
|
||||
inline bool match_prefix(const std::string& uri, const std::vector<std::string>& choices)
|
||||
{
|
||||
for (const auto &c : choices)
|
||||
{
|
||||
if (string::starts_with(uri, std::string("/") + c + std::string("/")))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user