Skip to content

Commit

Permalink
fs,test: add URL to string to fs.watch
Browse files Browse the repository at this point in the history
Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com>
PR-URL: #51346
Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io>
Reviewed-By: Moshe Atlow <moshe@atlow.co.il>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
  • Loading branch information
RafaelGSS authored and richardlau committed Mar 25, 2024
1 parent e9276ba commit 4adea6c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ const {
getValidatedPath,
getValidMode,
handleErrorFromBinding,
possiblyTransformPath,
preprocessSymlinkDestination,
Stats,
getStatFsFromBinding,
Expand Down Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion test/fixtures/permission/fs-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -353,4 +360,4 @@ const regularFile = __filename;
permission: 'FileSystemRead',
resource: path.toNamespacedPath(blockedFile),
}));
}
}

0 comments on commit 4adea6c

Please sign in to comment.