Browse Source

Backport (2-0-x) - Fix require on network share path (#12287)

* first pass at server/network require fix

* refactor for clarity
trop[bot] 7 years ago
parent
commit
6ff0d744ee
1 changed files with 12 additions and 1 deletions
  1. 12 1
      lib/renderer/init.js

+ 12 - 1
lib/renderer/init.js

@@ -141,7 +141,18 @@ if (nodeIntegration === 'true') {
 
   // Set the __filename to the path of html file if it is file: protocol.
   if (window.location.protocol === 'file:') {
-    var pathname = process.platform === 'win32' && window.location.pathname[0] === '/' ? window.location.pathname.substr(1) : window.location.pathname
+    const location = window.location
+    let pathname = location.pathname
+
+    if (process.platform === 'win32') {
+      if (pathname[0] === '/') pathname = pathname.substr(1)
+
+      const isWindowsNetworkSharePath = location.hostname.length > 0 && globalPaths[0].startsWith('\\')
+      if (isWindowsNetworkSharePath) {
+        pathname = `//${location.host}/${pathname}`
+      }
+    }
+
     global.__filename = path.normalize(decodeURIComponent(pathname))
     global.__dirname = path.dirname(global.__filename)