From 016110943c20e11e0611c7b4fcc2247266d1232c Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Tue, 2 Jan 2024 21:17:37 -0300 Subject: [PATCH] fs,test: add URL to string to fs.watch Signed-off-by: RafaelGSS --- lib/fs.js | 2 +- test/fixtures/permission/fs-read.js | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/fs.js b/lib/fs.js index 8ddbf18cdd4865..afd5757cf4310b 100644 --- a/lib/fs.js +++ b/lib/fs.js @@ -2451,7 +2451,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 +}