Skip to content

Commit

Permalink
Merge pull request #339 from zefrenchy/master
Browse files Browse the repository at this point in the history
Added unsafe load functions (allows absolute file for special cases)
  • Loading branch information
The-EDev authored Feb 11, 2022
2 parents 5a651b0 + ebef1ca commit 610e824
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion include/crow/http_response.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,16 @@ namespace crow
int statResult;
};

///Return a static file as the response body
/// Return a static file as the response body
void set_static_file_info(std::string path)
{
utility::sanitize_filename(path);
set_static_file_info_unsafe(path);
}

/// Return a static file as the response body without sanitizing the path (use set_static_file_info instead)
void set_static_file_info_unsafe(std::string path)
{
file_info.path = path;
file_info.statResult = stat(file_info.path.c_str(), &file_info.statbuf);
#ifdef CROW_ENABLE_COMPRESSION
Expand Down
10 changes: 10 additions & 0 deletions include/crow/mustache.h
Original file line number Diff line number Diff line change
Expand Up @@ -637,11 +637,21 @@ namespace crow
return detail::get_loader_ref()(filename_sanitized);
}

inline std::string load_text_unsafe(const std::string& filename)
{
return detail::get_loader_ref()(filename);
}

inline template_t load(const std::string& filename)
{
std::string filename_sanitized(filename);
utility::sanitize_filename(filename_sanitized);
return compile(detail::get_loader_ref()(filename_sanitized));
}

inline template_t load_unsafe(const std::string& filename)
{
return compile(detail::get_loader_ref()(filename));
}
} // namespace mustache
} // namespace crow

0 comments on commit 610e824

Please sign in to comment.