File tree Expand file tree Collapse file tree 2 files changed +72
-1
lines changed
Expand file tree Collapse file tree 2 files changed +72
-1
lines changed Original file line number Diff line number Diff line change @@ -408,7 +408,7 @@ class Glob {
408408 this . #results. add ( path ) ;
409409 }
410410
411- if ( ! isDirectory ) {
411+ if ( ! isDirectory && stat !== null ) {
412412 return ;
413413 }
414414
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ require ( '../common' ) ;
4+
5+ const assert = require ( 'node:assert' ) ;
6+ const fs = require ( 'node:fs' ) ;
7+ const path = require ( 'node:path' ) ;
8+
9+ const { spawnSyncAndAssert } = require ( '../common/child_process' ) ;
10+ const tmpdir = require ( '../common/tmpdir' ) ;
11+
12+ // This test verifies that fs.globSync() works correctly udner permission model
13+ // when --allow-fs-read is granted only to the certain directory
14+
15+ // Example:
16+ // Directory structure:
17+ // somedir/
18+ // file1.js
19+ // sample.js
20+ //
21+ // Command:
22+ // node --permission --allow-fs-read=somedir/ sample.js
23+ //
24+ // Code:
25+ // fs.globSync('somedir/*') <- sould find file1.js
26+
27+ tmpdir . refresh ( ) ;
28+
29+ const someDir = tmpdir . resolve ( 'somedir' ) ;
30+ const script = tmpdir . resolve ( 'sample.js' ) ;
31+
32+ fs . mkdirSync ( someDir ) ;
33+ fs . writeFileSync (
34+ path . join ( someDir , 'file1.js' ) ,
35+ 'console.log("test");'
36+ ) ;
37+
38+ fs . writeFileSync (
39+ script ,
40+ `
41+ 'use strict';
42+ const fs = require('fs');
43+ const matches = fs.globSync('somedir/*');
44+ console.log(JSON.stringify(matches));
45+ `
46+ ) ;
47+
48+ spawnSyncAndAssert (
49+ process . execPath ,
50+ [
51+ '--permission' ,
52+ `--allow-fs-read=${ someDir } ` ,
53+ script ,
54+ ] ,
55+ {
56+ cwd : tmpdir . path ,
57+ } ,
58+ {
59+ stdout ( output ) {
60+ assert . deepStrictEqual (
61+ JSON . parse ( output ) ,
62+ [ 'somedir/file1.js' ]
63+ ) ;
64+ return true ;
65+ } ,
66+ stderr ( output ) {
67+ assert . doesNotMatch ( output , / E R R _ A C C E S S _ D E N I E D / ) ;
68+ return true ;
69+ } ,
70+ }
71+ ) ;
You can’t perform that action at this time.
0 commit comments