fix: don't allow files to be nested inside other files #1052
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Resolves #1049
Fix issue with nested path write in
Volume
and add testsIssue
The
Volume
class had an issue where files could incorrectly be nested inside other files. It was possible to read/write files nested inside other files which should not be allowed.Solution
To resolve this issue, I updated the
writeFileSync
andreadFileSync
methods in the Volume class to check if the parent path of the file being written to is a file. If it is, we throw an ENOTDIR error. Additionally, we check if a path being read is a directory and throw an EISDIR error if so.Changes Made
Updated
writeFileSync
involume.ts
:Updated
readFileSync
involume.ts
:Added Tests
I added a new test file volume-issue.test.ts under src/tests/volume/ to cover these cases. They all pass:
Thank you for allowing me to contribute to this project. I learned a lot, and if there is anything else that you need me to change, please let me know!