From 4adea6c405028c2bed4c35927e7291c92ed9563f Mon Sep 17 00:00:00 2001 From: Rafael Gonzaga Date: Fri, 5 Jan 2024 00:49:07 +0000 Subject: [PATCH] fs,test: add URL to string to fs.watch Signed-off-by: RafaelGSS PR-URL: https://github.com/nodejs/node/pull/51346 Reviewed-By: Yagiz Nizipli Reviewed-By: Moshe Atlow Reviewed-By: Luigi Pinca Reviewed-By: Benjamin Gruenbaum --- lib/fs.js | 3 +-- test/fixtures/permission/fs-read.js | 9 ++++++++- 2 files changed, 9 insertions(+), 3 deletions(-) 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 +}