aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/bindings/ZigGlobalObject.cpp
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-04 17:08:54 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-05-04 17:09:10 -0700
commit8e4f777d352b1c55f510ed8b81629733f7c32cd1 (patch)
treea44ec38bd9a426a7c9416aa22b7e2c9629c9ef38 /src/bun.js/bindings/ZigGlobalObject.cpp
parent8b6dd0c7e1c78a37da693dc216b18f32caa61927 (diff)
downloadbun-8e4f777d352b1c55f510ed8b81629733f7c32cd1.tar.gz
bun-8e4f777d352b1c55f510ed8b81629733f7c32cd1.tar.zst
bun-8e4f777d352b1c55f510ed8b81629733f7c32cd1.zip
Throw error on non-file url
Diffstat (limited to 'src/bun.js/bindings/ZigGlobalObject.cpp')
-rw-r--r--src/bun.js/bindings/ZigGlobalObject.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp
index b969acf4c..2dbccc1f1 100644
--- a/src/bun.js/bindings/ZigGlobalObject.cpp
+++ b/src/bun.js/bindings/ZigGlobalObject.cpp
@@ -1124,6 +1124,10 @@ JSC_DEFINE_HOST_FUNCTION(functionFileURLToPath, (JSC::JSGlobalObject * globalObj
if (!domURL) {
if (arg0.isString()) {
auto url = WTF::URL(arg0.toWTFString(globalObject));
+ if (!url.protocolIs("file"_s)) {
+ throwTypeError(globalObject, scope, "Argument must be a file URL"_s);
+ return JSC::JSValue::encode(JSC::JSValue {});
+ }
RETURN_IF_EXCEPTION(scope, JSC::JSValue::encode(JSC::jsUndefined()));
RELEASE_AND_RETURN(scope, JSValue::encode(jsString(vm, url.fileSystemPath())));
}
@@ -1131,7 +1135,13 @@ JSC_DEFINE_HOST_FUNCTION(functionFileURLToPath, (JSC::JSGlobalObject * globalObj
return JSC::JSValue::encode(JSC::JSValue {});
}
- return JSC::JSValue::encode(JSC::jsString(vm, domURL->href().fileSystemPath()));
+ auto& url = domURL->href();
+ if (!url.protocolIs("file"_s)) {
+ throwTypeError(globalObject, scope, "Argument must be a file URL"_s);
+ return JSC::JSValue::encode(JSC::JSValue {});
+ }
+
+ return JSC::JSValue::encode(JSC::jsString(vm, url.fileSystemPath()));
}
JSC_DEFINE_CUSTOM_GETTER(noop_getter, (JSGlobalObject*, EncodedJSValue, PropertyName))