diff options
Diffstat (limited to 'src/install/install.zig')
-rw-r--r-- | src/install/install.zig | 49 |
1 files changed, 41 insertions, 8 deletions
diff --git a/src/install/install.zig b/src/install/install.zig index a91a3dd93..7b8d71bad 100644 --- a/src/install/install.zig +++ b/src/install/install.zig @@ -4475,7 +4475,23 @@ pub const PackageManager = struct { for (scoped.scopes, 0..) |name, i| { var registry = scoped.registries[i]; if (registry.url.len == 0) registry.url = base.url; - try this.registries.put(allocator, Npm.Registry.Scope.hash(name), try Npm.Registry.Scope.fromAPI(name, registry, allocator, env)); + try this.registries.put(allocator, Npm.Registry.Scope.hash(name), Npm.Registry.Scope.fromAPI(name, registry, allocator, env) catch |err| { + if (err == error.InvalidURL) { + log.addErrorFmt( + null, + logger.Loc.Empty, + allocator, + "{} is not a valid registry URL", + .{ + strings.QuotedFormatter{ + .text = registry.url, + }, + }, + ) catch unreachable; + } + + return err; + }); } } @@ -4588,12 +4604,21 @@ pub const PackageManager = struct { { const prev_scope = this.scope; var api_registry = std.mem.zeroes(Api.NpmRegistry); - api_registry.url = registry_; - api_registry.token = prev_scope.token; - this.scope = try Npm.Registry.Scope.fromAPI("", api_registry, allocator, env); - did_set = true; - // stage1 bug: break inside inline is broken - // break :load_registry; + var href = bun.JSC.URL.hrefFromString(bun.String.fromUTF8(registry_)); + if (href.tag == .Dead) { + try log.addErrorFmt(null, logger.Loc.Empty, bun.default_allocator, "${s} has invalid URL {}", .{ + registry_key, strings.QuotedFormatter{ + .text = registry_, + }, + }); + } else { + defer href.deref(); + + api_registry.token = prev_scope.token; + this.scope = try Npm.Registry.Scope.fromAPI("", api_registry, allocator, env); + api_registry.url = try href.toOwnedSlice(bun.default_allocator); + did_set = true; + } } } } @@ -4626,7 +4651,15 @@ pub const PackageManager = struct { if (cli.registry.len > 0 and strings.startsWith(cli.registry, "https://") or strings.startsWith(cli.registry, "http://")) { - this.scope.url = URL.parse(cli.registry); + if (URL.fromUTF8(instance.allocator, cli.registry)) |url| { + this.scope.url = url; + } else |_| { + try log.addErrorFmt(null, logger.Loc.Empty, bun.default_allocator, "--registry has invalid URL {}", .{ + strings.QuotedFormatter{ + .text = cli.registry, + }, + }); + } } if (cli.exact) { |