mirror of
https://github.com/falcosecurity/falco.git
synced 2025-09-10 02:59:38 +00:00
cleanup(falco): remove decode_uri as it is no longer used
Signed-off-by: Luca Guerra <luca@guerra.sh>
This commit is contained in:
@@ -72,22 +72,3 @@ TEST(FalcoUtils, parse_prometheus_interval)
|
|||||||
*/
|
*/
|
||||||
ASSERT_EQ(falco::utils::parse_prometheus_interval("200"), 0UL);
|
ASSERT_EQ(falco::utils::parse_prometheus_interval("200"), 0UL);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(FalcoUtils, decode_url)
|
|
||||||
{
|
|
||||||
ASSERT_EQ(
|
|
||||||
falco::utils::decode_uri("https://www.example.com?key1=value+1&key2=value%40%21%242&key3=value%253", true),
|
|
||||||
"https://www.example.com?key1=value 1&key2=value@!$2&key3=value%3");
|
|
||||||
|
|
||||||
ASSERT_EQ(
|
|
||||||
falco::utils::decode_uri("https://download.falco.org/?prefix=driver/3.0.1%2Bdriver/x86_64/", true),
|
|
||||||
"https://download.falco.org/?prefix=driver/3.0.1+driver/x86_64/");
|
|
||||||
|
|
||||||
ASSERT_EQ(
|
|
||||||
falco::utils::decode_uri("https://example.com/hello%20world", true),
|
|
||||||
"https://example.com/hello world");
|
|
||||||
|
|
||||||
ASSERT_EQ(
|
|
||||||
falco::utils::decode_uri("https://example.com/helloworld", true),
|
|
||||||
"https://example.com/helloworld");
|
|
||||||
}
|
|
||||||
|
@@ -20,7 +20,6 @@ limitations under the License.
|
|||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
|
||||||
#include "falco_common.h"
|
|
||||||
#include "falco_utils.h"
|
#include "falco_utils.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
@@ -161,80 +160,6 @@ void readfile(const std::string& filename, std::string& data)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// URI-decodes the given string by replacing percent-encoded
|
|
||||||
// characters with the actual character. Returns the decoded string.
|
|
||||||
//
|
|
||||||
// When plus_as_space is true, non-encoded plus signs in the query are decoded as spaces.
|
|
||||||
// (http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.1)
|
|
||||||
std::string decode_uri(const std::string& str, bool plus_as_space)
|
|
||||||
{
|
|
||||||
std::string decoded_str;
|
|
||||||
bool in_query = false;
|
|
||||||
std::string::const_iterator it = str.begin();
|
|
||||||
std::string::const_iterator end = str.end();
|
|
||||||
while(it != end)
|
|
||||||
{
|
|
||||||
char c = *it++;
|
|
||||||
if(c == '?')
|
|
||||||
{
|
|
||||||
in_query = true;
|
|
||||||
}
|
|
||||||
// spaces may be encoded as plus signs in the query
|
|
||||||
if(in_query && plus_as_space && c == '+')
|
|
||||||
{
|
|
||||||
c = ' ';
|
|
||||||
}
|
|
||||||
else if(c == '%')
|
|
||||||
{
|
|
||||||
if (it == end)
|
|
||||||
{
|
|
||||||
throw falco_exception("URI encoding: no hex digit following percent sign in " + str);
|
|
||||||
}
|
|
||||||
char hi = *it++;
|
|
||||||
if (it == end)
|
|
||||||
{
|
|
||||||
throw falco_exception("URI encoding: two hex digits must follow percent sign in " + str);
|
|
||||||
}
|
|
||||||
char lo = *it++;
|
|
||||||
if (hi >= '0' && hi <= '9')
|
|
||||||
{
|
|
||||||
c = hi - '0';
|
|
||||||
}
|
|
||||||
else if (hi >= 'A' && hi <= 'F')
|
|
||||||
{
|
|
||||||
c = hi - 'A' + 10;
|
|
||||||
}
|
|
||||||
else if (hi >= 'a' && hi <= 'f')
|
|
||||||
{
|
|
||||||
c = hi - 'a' + 10;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw falco_exception("URI encoding: not a hex digit found in " + str);
|
|
||||||
}
|
|
||||||
c *= 16;
|
|
||||||
if (lo >= '0' && lo <= '9')
|
|
||||||
{
|
|
||||||
c += lo - '0';
|
|
||||||
}
|
|
||||||
else if (lo >= 'A' && lo <= 'F')
|
|
||||||
{
|
|
||||||
c += lo - 'A' + 10;
|
|
||||||
}
|
|
||||||
else if (lo >= 'a' && lo <= 'f')
|
|
||||||
{
|
|
||||||
c += lo - 'a' + 10;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw falco_exception("URI encoding: not a hex digit");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
decoded_str += c;
|
|
||||||
}
|
|
||||||
return decoded_str;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace network
|
namespace network
|
||||||
{
|
{
|
||||||
bool is_unix_scheme(const std::string& url)
|
bool is_unix_scheme(const std::string& url)
|
||||||
|
@@ -52,8 +52,6 @@ void readfile(const std::string& filename, std::string& data);
|
|||||||
|
|
||||||
uint32_t hardware_concurrency();
|
uint32_t hardware_concurrency();
|
||||||
|
|
||||||
std::string decode_uri(const std::string& str, bool plus_as_space);
|
|
||||||
|
|
||||||
namespace network
|
namespace network
|
||||||
{
|
{
|
||||||
static const std::string UNIX_SCHEME("unix://");
|
static const std::string UNIX_SCHEME("unix://");
|
||||||
|
Reference in New Issue
Block a user