Skip to content

Commit 882a05f

Browse files
committed
escape root path for JS correctly
or the application cannot start in directory like C:\xdk
1 parent e223119 commit 882a05f

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/renderer/shell_content_renderer_client.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,10 +285,14 @@ void ShellContentRendererClient::InstallNodeSymbols(
285285

286286
if (use_node) {
287287
RenderViewImpl* rv = RenderViewImpl::FromWebView(frame->view());
288+
std::string root_path = rv->renderer_preferences_.nw_app_root_path.AsUTF8Unsafe();
289+
#if defined(OS_WIN)
290+
ReplaceChars(root_path, "\\", "\\\\", &root_path);
291+
#endif
288292
v8::Local<v8::Script> script = v8::Script::New(v8::String::New((
289293
// Make node's relative modules work
290294
"if (!process.mainModule.filename) {"
291-
" var root = '" + rv->renderer_preferences_.nw_app_root_path.AsUTF8Unsafe() + "';"
295+
" var root = '" + root_path + "';"
292296
#if defined(OS_WIN)
293297
"process.mainModule.filename = decodeURIComponent(window.location.pathname.substr(1));"
294298
#else
@@ -299,6 +303,7 @@ void ShellContentRendererClient::InstallNodeSymbols(
299303
"process.mainModule.loaded = true;"
300304
"}").c_str()
301305
));
306+
CHECK(script);
302307
script->Run();
303308
}
304309

0 commit comments

Comments
 (0)