Skip to content

Commit 8363b95

Browse files
castholmandrewrk
authored andcommitted
Fix "dependency path outside project" error for nested local path dependencies
Closes #23076
1 parent 711b0fe commit 8363b95

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/Package/Fetch.zig

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,17 @@ pub fn run(f: *Fetch) RunError!void {
331331
// prefix of "p/$hash/".
332332
const prefix_len: usize = if (f.job_queue.read_only) 0 else "p/".len;
333333
const parent_sub_path = f.parent_package_root.sub_path;
334-
const end = std.mem.indexOfScalarPos(u8, parent_sub_path, prefix_len, fs.path.sep) orelse
335-
parent_sub_path.len;
336-
const expected_prefix = parent_sub_path[prefix_len..end];
334+
const end = find_end: {
335+
if (parent_sub_path.len > prefix_len) {
336+
// Use `isSep` instead of `indexOfScalarPos` to account for
337+
// Windows accepting both `\` and `/` as path separators.
338+
for (parent_sub_path[prefix_len..], prefix_len..) |c, i| {
339+
if (std.fs.path.isSep(c)) break :find_end i;
340+
}
341+
}
342+
break :find_end parent_sub_path.len;
343+
};
344+
const expected_prefix = parent_sub_path[0..end];
337345
if (!std.mem.startsWith(u8, pkg_root.sub_path, expected_prefix)) {
338346
return f.fail(
339347
f.location_tok,

0 commit comments

Comments
 (0)