aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/URLDecomposition.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-16 16:45:26 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-09-16 16:45:26 -0700
commitf55b9a853064f276c918fe3f91df55c48f901f86 (patch)
tree116eb307fa1d6c055cc613e1700c7f3228a7159b /src/bun.js/bindings/URLDecomposition.cpp
parentda6f954e0dd851af4ad206de74fbcd500d3712e6 (diff)
downloadbun-f55b9a853064f276c918fe3f91df55c48f901f86.tar.gz
bun-f55b9a853064f276c918fe3f91df55c48f901f86.tar.zst
bun-f55b9a853064f276c918fe3f91df55c48f901f86.zip
Fix `origin` missing `protocol` in `URL`
Fixes https://github.com/oven-sh/bun/issues/1244
Diffstat (limited to 'src/bun.js/bindings/URLDecomposition.cpp')
-rw-r--r--src/bun.js/bindings/URLDecomposition.cpp16
1 files changed, 15 insertions, 1 deletions
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<uint32_t>(*port));
}
String URLDecomposition::protocol() const