Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: return 404 for ENOTDIR #162

Merged
merged 5 commits into from
Jan 16, 2022
Merged

fix: return 404 for ENOTDIR #162

merged 5 commits into from
Jan 16, 2022

Conversation

kalinkrustev
Copy link
Contributor

Inert will return error 500 for non-existing files, when part of the path resembles an existing file.
For example if /a/b/c.html is existing file, requesting /a/b/c.html/d will return 500 instead of 404.

ENOTDIR is listed here https://nodejs.org/api/errors.html#common-system-errors

Copy link
Contributor

@kanongil kanongil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. This seems like a valid issue, and a 404 is probably the appropriate response.

However, we can't merge this PR without a new test case, which tests this.

@kalinkrustev
Copy link
Contributor Author

OK, I will try to prepare some tests

@kalinkrustev
Copy link
Contributor Author

tests should be ok now

@kanongil
Copy link
Contributor

Hmm, I'm afraid that this error is not used on windows, which causes the coverage check to fail. This is complicated to fix, since the test will need to inject a fake error on windows (inside an if (process.platform === 'win32') { … }) like here:

inert/test/file.js

Lines 1073 to 1078 in ae77ea5

const orig = InertFs.fstat;
InertFs.fstat = function (fd) { // can return EIO error
InertFs.fstat = orig;
throw new Error('failed');
};

@kalinkrustev
Copy link
Contributor Author

check again, should be ok now

Copy link
Contributor

@kanongil kanongil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clever fix. We are almost there, just a few more details to finish.

lib/fs.js Outdated Show resolved Hide resolved
@devinivy
Copy link
Member

Thanks to both of you for working through this— it's a good fix and looks very close to 100% complete as Gil mentioned above. 💎 👍

@kanongil
Copy link
Contributor

Ping for merge and publish?

@devinivy devinivy merged commit 67daaff into hapijs:master Jan 16, 2022
@devinivy devinivy added this to the 6.0.5 milestone Jan 16, 2022
@devinivy devinivy added the bug Bug or defect label Jan 16, 2022
@devinivy devinivy self-assigned this Jan 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or defect
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants