From a91c95ac46a2f0f0c6a42dfce2822624c2410edd Mon Sep 17 00:00:00 2001 From: Xmader Date: Wed, 23 Oct 2019 17:12:14 -0400 Subject: [PATCH 1/2] add a hacky and direct workaround to fix #525 --- lib/http-server.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/http-server.js b/lib/http-server.js index 4cdd1b1c8..bb45ee2a0 100644 --- a/lib/http-server.js +++ b/lib/http-server.js @@ -6,8 +6,32 @@ var fs = require('fs'), auth = require('basic-auth'), httpProxy = require('http-proxy'), corser = require('corser'), + path = require('path'), secureCompare = require('secure-compare'); +// a hacky and direct workaround to fix https://github.com/http-party/http-server/issues/525 +function getCaller() { + try { + var stack = new Error().stack; + var stackLines = stack.split('\n'); + var callerStack = stackLines[3]; + return callerStack.match(/at (.+) \(/)[1]; + } + catch (error) { + return ''; + } +} + +var _pathNormalize = path.normalize; +path.normalize = function (p) { + var caller = getCaller(); + var result = _pathNormalize(p); + if (caller === 'decodePathname') { + result = result.replace(/\\/g, '/'); + } + return result; +}; + // // Remark: backwards compatibility for previous // case convention of HTTP From c4956ecc93fbf90e4074289fb6f7699107af9132 Mon Sep 17 00:00:00 2001 From: Xmader Date: Wed, 23 Oct 2019 17:15:54 -0400 Subject: [PATCH 2/2] add comments --- lib/http-server.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/http-server.js b/lib/http-server.js index bb45ee2a0..c2558e135 100644 --- a/lib/http-server.js +++ b/lib/http-server.js @@ -26,6 +26,7 @@ var _pathNormalize = path.normalize; path.normalize = function (p) { var caller = getCaller(); var result = _pathNormalize(p); + // https://github.com/jfhbrook/node-ecstatic/blob/master/lib/ecstatic.js#L20 if (caller === 'decodePathname') { result = result.replace(/\\/g, '/'); }