Skip to content

Commit

Permalink
Merge pull request #282 from niieani/fix-nested-access
Browse files Browse the repository at this point in the history
fix: throw ENOTDIR when trying to open an incorrect path (nested under existing file)
  • Loading branch information
tschaub authored Nov 25, 2019
2 parents b36d90f + 9adc82f commit 98ba9b6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ FileSystem.prototype.getItem = function(filepath) {
throw new FSError('EACCES', filepath);
}
}
if (item instanceof File) {
throw new FSError('ENOTDIR', filepath);
}
item = item.getItem(name);
}
if (!item) {
Expand Down
10 changes: 10 additions & 0 deletions test/lib/binding.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,16 @@ describe('Binding', function() {
binding.read(fd, buffer, 0, 11, 0);
});
});

it('throws ENOTDIR when trying to open an incorrect path (nested under existing file)', function() {
const binding = new Binding(system);
assert.throws(function() {
binding.open(
path.join('mock-dir', 'two.txt', 'bogus-path'),
flags('r')
);
}, 'ENOTDIR');
});
});

describe('#write()', function() {
Expand Down

0 comments on commit 98ba9b6

Please sign in to comment.