jfhbrook / node-ecstatic

A static file server middleware that works with core http, express or on the CLI!
https://github.com/jfhbrook/node-ecstatic
MIT License
975 stars 194 forks source link

Windows Infinite 302 Redirection #260

Open nashaofu opened 5 years ago

nashaofu commented 5 years ago

https://github.com/jfhbrook/node-ecstatic/blob/ae7a39b1ecdbe3aa8c0162ab2c3f7365bf9a6d75/lib/ecstatic.js#L23-L31

Windows pathname parsing is incorrect

https://github.com/jfhbrook/node-ecstatic/blob/ae7a39b1ecdbe3aa8c0162ab2c3f7365bf9a6d75/lib/ecstatic.js#L393-L399 Or modify here to

if (!parsed.pathname.match(/\/$/)) {
  res.statusCode = 302;
  const q = parsed.query ? `?${parsed.query}` : '';
  res.setHeader('location', `${parsed.pathname}/${q}`);
  res.end();
  return;
}
bjornharrtell commented 5 years ago

Regressed in commit https://github.com/jfhbrook/node-ecstatic/commit/be6fc25a826f190b67f4d16158f9d67899e38ee4 which was also backported to 3.x series with https://github.com/jfhbrook/node-ecstatic/commit/d0e2bcf40e31d361f6cc419b4b5c2c7846e0dad6.