-
Notifications
You must be signed in to change notification settings - Fork 1
Completed abs_path new constructor for windows #2
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM after comments. Could you add some tests for this? Ty.
core/src/abs_path.rs
Outdated
| #[cfg(windows)] | ||
| fn new(original_str: &'a str) -> Result<Self, NormalizeError> { | ||
| if matches!(original_str.chars().next(), Some('a'..='z' | 'A'..='Z')) && &original_str[1..3] == ":\\" { | ||
| if matches!(original_str.chars().next(), Some('a'..='z' | 'A'..='Z')) && &original_str[1..4] == ":\\" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[1..4] panics if the string is shorter than 4 bytes. Use get(1..cursor) instead.
core/src/abs_path.rs
Outdated
| fn new(original_str: &'a str) -> Result<Self, NormalizeError> { | ||
| if matches!(original_str.chars().next(), Some('a'..='z' | 'A'..='Z')) && &original_str[1..3] == ":\\" { | ||
| if matches!(original_str.chars().next(), Some('a'..='z' | 'A'..='Z')) && &original_str[1..4] == ":\\" { | ||
| let cursor = 4; // e.g. "C:\\" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you define the cursor outside the if? That way we can use it as the upper bound when slicing instead of having 2 sources of truth.
Also, shouldn't it be set to 3? C:\ is 3 bytes long.
|
This is a quick fix. I would like to get nomad working on my Windows machine. Sorry I don't have more time today. I did address your comments. A couple notes:
|
Added correct absolute path validation for windows: https://learn.microsoft.com/en-us/answers/questions/862484/regex-to-validate-a-valid-windows-folder-directory