diff --git a/lib/filesystem.js b/lib/filesystem.js index 6e75101b..e50f153e 100644 --- a/lib/filesystem.js +++ b/lib/filesystem.js @@ -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) { diff --git a/test/lib/binding.spec.js b/test/lib/binding.spec.js index 7557044a..0239133c 100644 --- a/test/lib/binding.spec.js +++ b/test/lib/binding.spec.js @@ -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() {