zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit 8363b951788a666802d6bbd6364eb973e2dbc09a (tree)
parent 711b0fef58571761386fd8dcd8b9ea3df2283200
Author: Carl Ã…stholm <carl@astholm.se>
Date:   Tue,  4 Mar 2025 14:56:18 +0100

Fix "dependency path outside project" error for nested local path dependencies

Closes #23076

Diffstat:
Msrc/Package/Fetch.zig | 14+++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/Package/Fetch.zig b/src/Package/Fetch.zig @@ -331,9 +331,17 @@ pub fn run(f: *Fetch) RunError!void { // prefix of "p/$hash/". const prefix_len: usize = if (f.job_queue.read_only) 0 else "p/".len; const parent_sub_path = f.parent_package_root.sub_path; - const end = std.mem.indexOfScalarPos(u8, parent_sub_path, prefix_len, fs.path.sep) orelse - parent_sub_path.len; - const expected_prefix = parent_sub_path[prefix_len..end]; + const end = find_end: { + if (parent_sub_path.len > prefix_len) { + // Use `isSep` instead of `indexOfScalarPos` to account for + // Windows accepting both `\` and `/` as path separators. + for (parent_sub_path[prefix_len..], prefix_len..) |c, i| { + if (std.fs.path.isSep(c)) break :find_end i; + } + } + break :find_end parent_sub_path.len; + }; + const expected_prefix = parent_sub_path[0..end]; if (!std.mem.startsWith(u8, pkg_root.sub_path, expected_prefix)) { return f.fail( f.location_tok,