From 2d1e0dc2400a8ecf4789f795b8d0a58e30086451 Mon Sep 17 00:00:00 2001 From: Dylan Conway <35280289+dylan-conway@users.noreply.github.com> Date: Mon, 22 Jan 2024 19:57:20 -0800 Subject: [PATCH] trim correctly (#8388) Co-authored-by: dave caruso Co-authored-by: Jarred Sumner --- src/resolver/package_json.zig | 1 + src/resolver/resolver.zig | 4 ++-- src/string_immutable.zig | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/resolver/package_json.zig b/src/resolver/package_json.zig index 1220aafca3..10546363aa 100644 --- a/src/resolver/package_json.zig +++ b/src/resolver/package_json.zig @@ -1135,6 +1135,7 @@ pub const ExportsMap = struct { map_data_ranges[i] = key_range; map_data_entries[i] = this.visit(prop.value.?); + // safe to use "/" on windows. exports in package.json does not use "\\" if (strings.endsWithComptime(key, "/") or strings.containsChar(key, '*')) { expansion_keys[expansion_key_i] = Entry.Data.Map.MapEntry{ .value = map_data_entries[i], diff --git a/src/resolver/resolver.zig b/src/resolver/resolver.zig index 07eb4be30c..f6b71c7089 100644 --- a/src/resolver/resolver.zig +++ b/src/resolver/resolver.zig @@ -2251,13 +2251,13 @@ pub const Resolver = struct { fn handleESMResolution(r: *ThisResolver, esm_resolution_: ESModule.Resolution, abs_package_path: string, kind: ast.ImportKind, package_json: *PackageJSON, package_subpath: string) ?MatchResult { var esm_resolution = esm_resolution_; if (!((esm_resolution.status == .Inexact or esm_resolution.status == .Exact or esm_resolution.status == .ExactEndsWithStar) and - esm_resolution.path.len > 0 and esm_resolution.path[0] == '/')) + esm_resolution.path.len > 0 and esm_resolution.path[0] == std.fs.path.sep)) return null; const abs_esm_path: string = brk: { var parts = [_]string{ abs_package_path, - strings.withoutLeadingSlash(esm_resolution.path), + strings.withoutLeadingPathSeparator(esm_resolution.path), }; break :brk r.fs.absBuf(&parts, bufs(.esm_absolute_package_path_joined)); }; diff --git a/src/string_immutable.zig b/src/string_immutable.zig index de3215f9bb..af086ac2a7 100644 --- a/src/string_immutable.zig +++ b/src/string_immutable.zig @@ -698,6 +698,10 @@ pub fn withoutLeadingSlash(this: string) []const u8 { return std.mem.trimLeft(u8, this, "/"); } +pub fn withoutLeadingPathSeparator(this: string) []const u8 { + return std.mem.trimLeft(u8, this, &.{std.fs.path.sep}); +} + pub fn endsWithAny(self: string, str: string) bool { const end = self[self.len - 1]; for (str) |char| {