@@ -173,6 +173,31 @@ function copyObject(source) {
173173return target ;
174174}
175175
176+ const bufferSep = Buffer . from ( pathModule . sep ) ;
177+
178+ function join ( path , name ) {
179+ if ( ( typeof path === 'string' || isUint8Array ( path ) ) &&
180+ name === undefined ) {
181+ return path ;
182+ }
183+
184+ if ( typeof path === 'string' && isUint8Array ( name ) ) {
185+ const pathBuffer = Buffer . from ( pathModule . join ( path , pathModule . sep ) ) ;
186+ return Buffer . concat ( [ pathBuffer , name ] ) ;
187+ }
188+
189+ if ( typeof path === 'string' && typeof name === 'string' ) {
190+ return pathModule . join ( path , name ) ;
191+ }
192+
193+ if ( isUint8Array ( path ) && isUint8Array ( name ) ) {
194+ return Buffer . concat ( [ path , bufferSep , name ] ) ;
195+ }
196+
197+ throw new ERR_INVALID_ARG_TYPE (
198+ 'path' , [ 'string' , 'Buffer' ] , path ) ;
199+ }
200+
176201function getDirents ( path , [ names , types ] , callback ) {
177202let i ;
178203if ( typeof callback === 'function' ) {
@@ -185,7 +210,14 @@ function getDirents(path, [names, types], callback) {
185210const name = names [ i ] ;
186211const idx = i ;
187212toFinish ++ ;
188- lazyLoadFs ( ) . lstat ( pathModule . join ( path , name ) , ( err , stats ) => {
213+ let filepath ;
214+ try {
215+ filepath = join ( path , name ) ;
216+ } catch ( err ) {
217+ callback ( err ) ;
218+ return ;
219+ }
220+ lazyLoadFs ( ) . lstat ( filepath , ( err , stats ) => {
189221if ( err ) {
190222callback ( err ) ;
191223return ;
@@ -214,7 +246,14 @@ function getDirents(path, [names, types], callback) {
214246function getDirent ( path , name , type , callback ) {
215247if ( typeof callback === 'function' ) {
216248if ( type === UV_DIRENT_UNKNOWN ) {
217- lazyLoadFs ( ) . lstat ( pathModule . join ( path , name ) , ( err , stats ) => {
249+ let filepath ;
250+ try {
251+ filepath = join ( path , name ) ;
252+ } catch ( err ) {
253+ callback ( err ) ;
254+ return ;
255+ }
256+ lazyLoadFs ( ) . lstat ( filepath , ( err , stats ) => {
218257if ( err ) {
219258callback ( err ) ;
220259return ;
@@ -225,7 +264,7 @@ function getDirent(path, name, type, callback) {
225264callback ( null , new Dirent ( name , type ) ) ;
226265}
227266} else if ( type === UV_DIRENT_UNKNOWN ) {
228- const stats = lazyLoadFs ( ) . lstatSync ( pathModule . join ( path , name ) ) ;
267+ const stats = lazyLoadFs ( ) . lstatSync ( join ( path , name ) ) ;
229268return new DirentFromStats ( name , stats ) ;
230269} else {
231270return new Dirent ( name , type ) ;
0 commit comments