fix: don't treat Windows drive-letter colons as scaling delimiter#338
Conversation
The recipe-path parser used rsplit_once(':') to separate an optional
scaling factor, which broke Windows absolute paths like
C:\test\recipe.cook (the path was split into name "C" and factor
"\test\recipe.cook", failing as an invalid float).
Now the helper only splits when the right side parses as f64, so
drive-letter paths fall through unchanged.
Closes #335
Code ReviewThis is a clean, well-scoped fix. The core approach — parse What's Good
Concerns1. UX regression for typos (acknowledged in PR, but worth deciding) The original code gave a precise error for The new behavior treats it as a path and reports: That's genuinely confusing for a user who intended to scale. A lightweight heuristic could catch this in the callers — if 2. Missing test: Windows path with valid scaling
#[test]
fn splits_windows_path_with_scaling_factor() {
assert_eq!(
split_recipe_name_and_scaling_factor(r"C:\test\recipe.cook:2"),
Some((r"C:\test\recipe.cook", 2.0))
);
}3. Negative and zero scaling
SummaryThe fix is correct and the code quality is high. Two things I'd recommend before merging:
|
Summary
C:\test\recipe.cookwere being split on the drive-letter colon, producing the errorInvalid scaling factor for 'C': invalid float literal.split_recipe_name_and_scaling_factornow only splits when the right side actually parses asf64, so drive-letter paths fall through unchanged. ReturningOption<(&str, f64)>also let me drop the parse-and-abort logic in all three callers (recipe read,report,extract_ingredients).Behavioral note
A typo like
recipe.cook:abcno longer surfaces asInvalid scaling factor; it now flows through and reportsRecipe not found: recipe.cook:abc. I think that's clearer (the user gave a path; we report it doesn't exist), but happy to add an explicit "looks like a typo'd scaling factor" check if reviewers prefer.Test plan
cargo fmt --checkcargo clippy --all-targets -- -D warningscargo test(all existing tests + 5 new unit tests for the helper)cook recipe read seed/Breakfast/Easy\ Pancakes.cook:2still scales correctlycook recipe read 'C:\test\recipe.cook'now reports "Recipe not found" instead of the float-parse error