diff options
author | 2023-07-21 23:27:28 -0700 | |
---|---|---|
committer | 2023-07-21 23:27:28 -0700 | |
commit | 636cec03e10ab487b1df3057aaab60b4d2b02c99 (patch) | |
tree | fbf10b89dcd64270ba7fee1d78efba2b5caf2414 /src/install/install.zig | |
parent | 1ecd9f8a18da1af9f2090791b15a18ff3e68411d (diff) | |
download | bun-636cec03e10ab487b1df3057aaab60b4d2b02c99.tar.gz bun-636cec03e10ab487b1df3057aaab60b4d2b02c99.tar.zst bun-636cec03e10ab487b1df3057aaab60b4d2b02c99.zip |
Use WebKit's URL parser in fetch() and `bun install` (#3730)
* Use WebKit's URL parser in fetch() and `bun install`
* Allocate less memory
* Fix test
---------
Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
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) { |