From 0ba92c211e4a8e4ac7d519bd609706742166cfe8 Mon Sep 17 00:00:00 2001 From: Jaifroid Date: Fri, 2 Aug 2019 16:40:39 +0100 Subject: [PATCH] Better electron URL parsing Former-commit-id: 687e9a5632b7238a4c803235275f799c78852537 [formerly 5e1a1df7daa9ba76cf16ed496aedfae87d02ab24] Former-commit-id: c7b5904175e8c10d3288fb999d26a5f53d571a39 --- main.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/main.js b/main.js index 578a4f9c..b0ec5ee4 100644 --- a/main.js +++ b/main.js @@ -83,17 +83,20 @@ function createWindow() { app.on('ready', () => { protocol.registerFileProtocol('app', (request, callback) => { //protocol.registerHttpProtocol('app', (request, callback) => { - let url = request.url.replace(/^app:\/\/([./]*)(.*)$/, function(_p0, relPath, linkUrl) { + const url = request.url.replace(/^app:\/\/([^?#]*?)([^?#\/\\]+)(?:[#?].*$|$)/, function(_p0, relPath, linkUrl) { // // @TODO: Complete routine to recognize relative links below (../) // let i = 0; // let parsedPath = relPath.replace(/\.\.\//g, function(p0) { // i++; // }); - console.log(relPath + '+' + linkUrl); + console.log(relPath + '+' + linkUrl + '=>'); return relPath + linkUrl; }); + //let returnPath = path.normalize(`${__dirname}/${url}`); + let returnPath = __dirname + '/' + url; + console.log(returnPath); callback({ - path: path.normalize(`${__dirname}/${url}`) + path: returnPath // url: 'file://' + path.normalize(`${__dirname}/${url}`), // method: 'GET' });