Merge pull request #334 from CrowCpp/sanitize_absolute_path

fixed issue where absolute unix paths were not sanitized
This commit is contained in:
Farook Al-Sammarraie 2022-02-08 23:25:21 +03:00 committed by GitHub
commit a63b0806cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 2 deletions

View File

@ -632,7 +632,9 @@ namespace crow
inline std::string load_text(const std::string& filename)
{
return detail::get_loader_ref()(filename);
std::string filename_sanitized(filename);
utility::sanitize_filename(filename_sanitized);
return detail::get_loader_ref()(filename_sanitized);
}
inline template_t load(const std::string& filename)

View File

@ -694,7 +694,15 @@ namespace crow
}
else if ((c == '/') || (c == '\\'))
{
checkForSpecialEntries = true;
//TODO(EDev): uncomment below once #332 is merged
if (/*CROW_UNLIKELY(*/ i == 0 /*)*/) //Prevent Unix Absolute Paths (Windows Absolute Paths are prevented with `(c == ':')`)
{
data[i] = replacement;
}
else
{
checkForSpecialEntries = true;
}
}
}
}

View File

@ -2473,6 +2473,7 @@ TEST_CASE("sanitize_filename")
CHECK(sanitize_filename("abc/COM9") == "abc/_");
CHECK(sanitize_filename("abc/COM") == "abc/COM");
CHECK(sanitize_filename("abc/CON") == "abc/_");
CHECK(sanitize_filename("/abc/") == "_abc/");
}
TEST_CASE("get_port")