Skip to content

Commit

Permalink
Added path sanitation support for ~ and ~/.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed May 15, 2024
1 parent fd4db04 commit 7277122
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/rishka_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ inline double rishka_long_to_double(int64_t l) {
* @return A String containing the sanitized file path.
*/
inline String rishka_sanitize_path(String currentWorkingDirectory, char* path) {
if(strlen(path) == 1 && path[0] == '~')
return "/";

if(strcmp(currentWorkingDirectory.c_str(), path) == 0)
return currentWorkingDirectory;

if(strlen(path) >= 2 && path[0] == '~' && path[1] == '/')
return String(path).substring(1);

String segment, sanitizedPath = "",
fullPath = (currentWorkingDirectory == "/" ?
"" : currentWorkingDirectory) +
Expand Down

0 comments on commit 7277122

Please sign in to comment.