From f55b9a853064f276c918fe3f91df55c48f901f86 Mon Sep 17 00:00:00 2001 From: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> Date: Fri, 16 Sep 2022 16:45:26 -0700 Subject: Fix `origin` missing `protocol` in `URL` Fixes https://github.com/oven-sh/bun/issues/1244 --- src/bun.js/bindings/URLDecomposition.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/bun.js/bindings/URLDecomposition.cpp') diff --git a/src/bun.js/bindings/URLDecomposition.cpp b/src/bun.js/bindings/URLDecomposition.cpp index 84e734528..f13d6b093 100644 --- a/src/bun.js/bindings/URLDecomposition.cpp +++ b/src/bun.js/bindings/URLDecomposition.cpp @@ -31,7 +31,21 @@ namespace WebCore { String URLDecomposition::origin() const { - return fullURL().hostAndPort(); + auto fullURL = this->fullURL(); + auto protocol = fullURL.protocol(); + auto host = fullURL.host(); + auto port = fullURL.port(); + + if (protocol == "file"_s) + return "file://"_s; + + if (protocol.isEmpty() && host.isEmpty()) + return {}; + + if (!port) + return makeString(protocol, "://", host); + + return makeString(protocol, "://", host, ':', static_cast(*port)); } String URLDecomposition::protocol() const -- cgit v1.2.3