Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update path handling #159

Closed
ryardley opened this issue Oct 28, 2024 · 1 comment
Closed

update path handling #159

ryardley opened this issue Oct 28, 2024 · 1 comment

Comments

@ryardley
Copy link
Contributor

          _:warning: Potential issue_

Implement proper tilde expansion in file paths

Using file.to_string_lossy().starts_with("~") assumes that paths starting with ~ are absolute, but Rust does not automatically expand ~ to the user's home directory. This may lead to incorrect path handling.

Consider implementing tilde (~) expansion explicitly:

 if file.is_absolute() || file.to_string_lossy().starts_with("~") {
     return file.clone();
 }

+// Add tilde expansion
+let expanded_file = if file.to_string_lossy().starts_with("~") {
+    let home_dir = dirs::home_dir().unwrap_or_else(|| PathBuf::from("/"));
+    home_dir.join(file.strip_prefix("~").unwrap_or(file))
+} else {
+    file.clone()
+};
+
+return expanded_file;

This ensures that paths starting with ~ are correctly expanded to the user's home directory.

Committable suggestion was skipped due to low confidence.

Originally posted by @coderabbitai[bot] in #156 (comment)

@ryardley
Copy link
Contributor Author

resolved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant