我想/ok/ä.txt
从/very///bad/%D0%B9/../../../../../request/../ok/%C3%A4.txt
node.js中获取。我发现了以下方法:
var url = require('url'), path = require('path');
require('http').createServer(function (request, response) {
var file = null;
try {
file = path.normalize(decodeURI(url.parse(request.url).pathname));
} catch (e) {
}
console.log(file);
response.end();
}).listen(3002, '127.0.0.1');
是否存在一些更好的方法,没有 try/catch 块?