Check extensions on a directory before redirecting#107
Check extensions on a directory before redirecting#107cag wants to merge 2 commits intopillarjs:masterfrom
Conversation
index.js
Outdated
| debug('stat "%s"', path); | ||
| fs.stat(path, function onstat(err, stat) { | ||
| if (err && err.code === 'ENOENT' | ||
| var isDirectory = stat && stat.isDirectory(); |
There was a problem hiding this comment.
Stat will be undefined if there's an err.
There was a problem hiding this comment.
That's why I prefixed it with stat &&. That's idiomatic, right?
|
Hi! Thanks for your pull request, but it does not include any tests for the change you made, does not include documentation, and even breaks existing tests. According to the tests this change broke, this change is actually breaking a feature of this module. Can you explain more what you change is doing, how it compares to the current functionality, and why it breaking our existing tests? |
|
I changed the tests to reflect what I mean and fixed an issue. |
|
According to the CI, this is only failing on node 0.8 now due to some package.json parsing thing. I've written a test, modified a test, and made sure all the existing tests pass. Could you please consider this PR for the next release? |
|
Hi @cag! It looks like you never actually answered all my questions in #107 (comment) . So, since I didn't get an answer, I can only make assumptions on what you are trying to do based on the code changes. This is a breaking change and will have to wait for the next major version at some point. Currently directories are preferred over extension-less files, and changing this will not be a backwards-compatible change. |
|
Sorry, I was a bit headstrong and forgot to elaborate. You're right that this change may potentially break distributions that depend on this package, but my feeling is that the behavior change is the natural one. I changed the behavior of the extensions option so that for this: with Currently, I changed the description for one of your tests to reflect the above, but I have fixed my code changes so that they don't break your tests. |
|
Thanks, @cag! Yes, this change makes sense. The reason I bring up the it being a breaking change is because this conflict was known about when the extensions feature was added and it was decided at the time to prefer the directory over looking for a file with the given extension. Because of this history, I see your PR here as a proposal to change that behavior, not a bug fix. I hope that makes sense. |
|
That's totally fine. I didn't think of it as a bugfix. This is just the scenario I personally ran into in the wild. |
I decided to change the behavior on the send module in a project and discovered that I really wanted sendFile to send things.json for a GET request to things when stuff like things/1.json exist.