-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix(publish): create http tarball urls correcly #23223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d14e06e
6fb6f0d
2381393
991a43f
34a0315
a75ef08
feb3532
acfd99e
30c0b7a
6e44b54
dc3f562
b825166
7827ce2
e84a10b
268d4f3
09ce019
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,157 @@ | ||||||||||||||||||||||||||
| #include "root.h" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| #include "helpers.h" | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| using namespace JSC; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" BunString URL__getFileURLString(BunString* _Nonnull filePath) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| return Bun::toStringRef(WTF::URL::fileURLWithFileSystemPath(filePath->toWTFString()).stringWithoutFragmentIdentifier()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" size_t URL__originLength(const char* latin1_slice, size_t len) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| WTF::String string = WTF::StringView(latin1_slice, len, true).toString(); | ||||||||||||||||||||||||||
| if (!string) | ||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||
| WTF::URL url(string); | ||||||||||||||||||||||||||
| if (!url.isValid()) | ||||||||||||||||||||||||||
| return 0; | ||||||||||||||||||||||||||
| return url.pathStart(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" WTF::URL* URL__fromJS(EncodedJSValue encodedValue, JSC::JSGlobalObject* globalObject) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| auto throwScope = DECLARE_THROW_SCOPE(globalObject->vm()); | ||||||||||||||||||||||||||
| JSC::JSValue value = JSC::JSValue::decode(encodedValue); | ||||||||||||||||||||||||||
| auto str = value.toWTFString(globalObject); | ||||||||||||||||||||||||||
| RETURN_IF_EXCEPTION(throwScope, nullptr); | ||||||||||||||||||||||||||
| if (str.isEmpty()) { | ||||||||||||||||||||||||||
| return nullptr; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| auto url = WTF::URL(str); | ||||||||||||||||||||||||||
| if (!url.isValid() || url.isNull()) | ||||||||||||||||||||||||||
| return nullptr; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return new WTF::URL(WTFMove(url)); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" BunString URL__getHrefFromJS(EncodedJSValue encodedValue, JSC::JSGlobalObject* globalObject) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| auto throwScope = DECLARE_THROW_SCOPE(globalObject->vm()); | ||||||||||||||||||||||||||
| JSC::JSValue value = JSC::JSValue::decode(encodedValue); | ||||||||||||||||||||||||||
| auto str = value.toWTFString(globalObject); | ||||||||||||||||||||||||||
| RETURN_IF_EXCEPTION(throwScope, { BunStringTag::Dead }); | ||||||||||||||||||||||||||
| if (str.isEmpty()) { | ||||||||||||||||||||||||||
| return { BunStringTag::Dead }; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| auto url = WTF::URL(str); | ||||||||||||||||||||||||||
| if (!url.isValid() || url.isEmpty()) | ||||||||||||||||||||||||||
| return { BunStringTag::Dead }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return Bun::toStringRef(url.string()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" BunString URL__getHref(BunString* _Nonnull input) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| auto&& str = input->toWTFString(); | ||||||||||||||||||||||||||
| auto url = WTF::URL(str); | ||||||||||||||||||||||||||
| if (!url.isValid() || url.isEmpty()) | ||||||||||||||||||||||||||
| return { BunStringTag::Dead }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return Bun::toStringRef(url.string()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" BunString URL__pathFromFileURL(BunString* _Nonnull input) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| auto&& str = input->toWTFString(); | ||||||||||||||||||||||||||
| auto url = WTF::URL(str); | ||||||||||||||||||||||||||
| if (!url.isValid() || url.isEmpty()) | ||||||||||||||||||||||||||
| return { BunStringTag::Dead }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return Bun::toStringRef(url.fileSystemPath()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" BunString URL__getHrefJoin(BunString* _Nonnull baseStr, BunString* _Nonnull relativeStr) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| auto base = baseStr->transferToWTFString(); | ||||||||||||||||||||||||||
| auto relative = relativeStr->transferToWTFString(); | ||||||||||||||||||||||||||
| auto url = WTF::URL(WTF::URL(base), relative); | ||||||||||||||||||||||||||
| if (!url.isValid() || url.isEmpty()) | ||||||||||||||||||||||||||
| return { BunStringTag::Dead }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return Bun::toStringRef(url.string()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" WTF::URL* URL__fromString(BunString* _Nonnull input) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| auto&& str = input->toWTFString(); | ||||||||||||||||||||||||||
| auto url = WTF::URL(str); | ||||||||||||||||||||||||||
| if (!url.isValid()) | ||||||||||||||||||||||||||
| return nullptr; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return new WTF::URL(WTFMove(url)); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" BunString URL__protocol(WTF::URL* _Nonnull url) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| return Bun::toStringRef(url->protocol().toStringWithoutCopying()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" void URL__setProtocol(WTF::URL* url, BunString newProtocol) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| String newProtocolStr = newProtocol.toWTFString(BunString::ZeroCopy); | ||||||||||||||||||||||||||
| url->setProtocol(newProtocolStr); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+103
to
+107
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add null check for url parameter. The function dereferences Apply this diff to add a null check: extern "C" void URL__setProtocol(WTF::URL* url, BunString newProtocol)
{
+ if (!url)
+ return;
String newProtocolStr = newProtocol.toWTFString(BunString::ZeroCopy);
url->setProtocol(newProtocolStr);
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" void URL__deinit(WTF::URL* _Nonnull url) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| delete url; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" BunString URL__href(WTF::URL* _Nonnull url) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| return Bun::toStringRef(url->string()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" BunString URL__username(WTF::URL* _Nonnull url) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| return Bun::toStringRef(url->user()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" BunString URL__password(WTF::URL* _Nonnull url) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| return Bun::toStringRef(url->password()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" BunString URL__search(WTF::URL* _Nonnull url) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| return Bun::toStringRef(url->query().toStringWithoutCopying()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" BunString URL__host(WTF::URL* _Nonnull url) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| return Bun::toStringRef(url->host().toStringWithoutCopying()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| extern "C" BunString URL__hostname(WTF::URL* _Nonnull url) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| return Bun::toStringRef(url->hostAndPort()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" uint32_t URL__port(WTF::URL* _Nonnull url) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| auto port = url->port(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (port.has_value()) { | ||||||||||||||||||||||||||
| return port.value(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return std::numeric_limits<uint32_t>::max(); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| extern "C" BunString URL__pathname(WTF::URL* _Nonnull url) | ||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| return Bun::toStringRef(url->path().toStringWithoutCopying()); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.