Skip to content

Conversation

@landonwork
Copy link

Copy link
Contributor

@noib3 noib3 left a 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.

#[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] == ":\\" {
Copy link
Contributor

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.

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:\\"
Copy link
Contributor

@noib3 noib3 Nov 30, 2025

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.

@landonwork
Copy link
Author

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:

  • I made a small test module in abs_path.rs because the tests in the tests folder won't compile. I believe the Unix-specific tests are still trying to compile because cfg_attr is not the same as cfg.
  • I had to adjust some values where MAIN_SEPARATOR_STR.len() was previously sufficient. I added 2 in places using a cfg! conditional, but this should probably be made a constant.

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

Successfully merging this pull request may close these issues.

2 participants