Skip to content

Commit f96fc99

Browse files
committedNov 10, 2019
Merge branch 'master' into test-on-windows
2 parents 8028337 + c1ea830 commit f96fc99

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed
 

‎lib/http-server.js

+25
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,33 @@ var fs = require('fs'),
66
auth = require('basic-auth'),
77
httpProxy = require('http-proxy'),
88
corser = require('corser'),
9+
path = require('path'),
910
secureCompare = require('secure-compare');
1011

12+
// a hacky and direct workaround to fix https://github.com/http-party/http-server/issues/525
13+
function getCaller() {
14+
try {
15+
var stack = new Error().stack;
16+
var stackLines = stack.split('\n');
17+
var callerStack = stackLines[3];
18+
return callerStack.match(/at (.+) \(/)[1];
19+
}
20+
catch (error) {
21+
return '';
22+
}
23+
}
24+
25+
var _pathNormalize = path.normalize;
26+
path.normalize = function (p) {
27+
var caller = getCaller();
28+
var result = _pathNormalize(p);
29+
// https://github.com/jfhbrook/node-ecstatic/blob/master/lib/ecstatic.js#L20
30+
if (caller === 'decodePathname') {
31+
result = result.replace(/\\/g, '/');
32+
}
33+
return result;
34+
};
35+
1136
//
1237
// Remark: backwards compatibility for previous
1338
// case convention of HTTP

0 commit comments

Comments
 (0)
Please sign in to comment.