diff --git a/lib/http-server.js b/lib/http-server.js index 9bd50a63..626a5a84 100644 --- a/lib/http-server.js +++ b/lib/http-server.js @@ -6,8 +6,33 @@ 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); + // https://github.com/jfhbrook/node-ecstatic/blob/master/lib/ecstatic.js#L20 + if (caller === 'decodePathname') { + result = result.replace(/\\/g, '/'); + } + return result; +}; + // // Remark: backwards compatibility for previous // case convention of HTTP