diff options
author | Anna Henningsen <anna@addaleax.net> | 2022-01-30 00:05:36 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2022-03-07 17:57:54 +0300 |
commit | 64832c12b1a0f77e38ed7614aaa106b7a832fdbf (patch) | |
tree | 992988de1789e5c278872064ea55ff420449dfee /src/node_api.cc | |
parent | 4158d62dec8cce190c7184457bc7fcef6b43f7da (diff) |
src: return proper URLs from node_api_get_module_file_name
Using `file://${path}` does not properly escape special URL characters.
PR-URL: https://github.com/nodejs/node/pull/41758
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Diffstat (limited to 'src/node_api.cc')
-rw-r--r-- | src/node_api.cc | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/node_api.cc b/src/node_api.cc index 82e228bb954..60fbe96b8ef 100644 --- a/src/node_api.cc +++ b/src/node_api.cc @@ -9,6 +9,7 @@ #include "node_buffer.h" #include "node_errors.h" #include "node_internals.h" +#include "node_url.h" #include "threadpoolwork-inl.h" #include "tracing/traced_value.h" #include "util-inl.h" @@ -589,13 +590,13 @@ void napi_module_register_by_symbol(v8::Local<v8::Object> exports, if (module->ToObject(context).ToLocal(&modobj) && modobj->Get(context, node_env->filename_string()).ToLocal(&filename_js) && filename_js->IsString()) { - node::Utf8Value filename(node_env->isolate(), filename_js); // Cast + node::Utf8Value filename(node_env->isolate(), filename_js); // Turn the absolute path into a URL. Currently the absolute path is always // a file system path. // TODO(gabrielschulhof): Pass the `filename` through unchanged if/when we // receive it as a URL already. - module_filename = std::string("file://") + (*filename); + module_filename = node::url::URL::FromFilePath(filename.ToString()).href(); } // Create a new napi_env for this specific module. |