diff --git a/lib/fs.js b/lib/fs.js index c15fd2904d3bee..6a456bcd5acffb 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -109,7 +109,6 @@ const { getValidatedPath, getValidMode, handleErrorFromBinding, - possiblyTransformPath, preprocessSymlinkDestination, Stats, getStatFsFromBinding, @@ -2451,7 +2450,7 @@ function watch(filename, options, listener) { let watcher; const watchers = require('internal/fs/watchers'); - const path = possiblyTransformPath(filename); + const path = getValidatedPath(filename); // TODO(anonrig): Remove non-native watcher when/if libuv supports recursive. // As of November 2022, libuv does not support recursive file watch on all platforms, // e.g. Linux due to the limitations of inotify. diff --git a/test/fixtures/permission/fs-read.js b/test/fixtures/permission/fs-read.js index 5b2035628c38d3..aa210243292ed0 100644 --- a/test/fixtures/permission/fs-read.js +++ b/test/fixtures/permission/fs-read.js @@ -265,6 +265,13 @@ const regularFile = __filename; permission: 'FileSystemRead', resource: path.toNamespacedPath(blockedFile), })); + assert.throws(() => { + fs.watch(blockedFileURL, () => {}); + }, common.expectsError({ + code: 'ERR_ACCESS_DENIED', + permission: 'FileSystemRead', + resource: path.toNamespacedPath(blockedFile), + })); // doesNotThrow fs.readdir(allowedFolder, (err) => { @@ -353,4 +360,4 @@ const regularFile = __filename; permission: 'FileSystemRead', resource: path.toNamespacedPath(blockedFile), })); -} \ No newline at end of file +}