Skip to content

fix: return 404 for ENOTDIR#162

Merged
devinivy merged 5 commits intohapijs:masterfrom
kalinkrustev:patch-1
Jan 16, 2022
Merged

fix: return 404 for ENOTDIR#162
devinivy merged 5 commits intohapijs:masterfrom
kalinkrustev:patch-1

Conversation

@kalinkrustev
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

OK, I will try to prepare some tests

@kalinkrustev
Copy link
Copy Markdown
Contributor Author

tests should be ok now

@kanongil
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

check again, should be ok now

Copy link
Copy Markdown
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.

@devinivy
Copy link
Copy Markdown
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
Copy Markdown
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.

3 participants