@@ -144,6 +144,31 @@ function copyObject(source) {
144144 return target ;
145145}
146146
147+ const bufferSep = Buffer . from ( pathModule . sep ) ;
148+
149+ function join ( path , name ) {
150+ if ( ( typeof path === 'string' || isUint8Array ( path ) ) &&
151+ name === undefined ) {
152+ return path ;
153+ }
154+
155+ if ( typeof path === 'string' && isUint8Array ( name ) ) {
156+ const pathBuffer = Buffer . from ( pathModule . join ( path , pathModule . sep ) ) ;
157+ return Buffer . concat ( [ pathBuffer , name ] ) ;
158+ }
159+
160+ if ( typeof path === 'string' && typeof name === 'string' ) {
161+ return pathModule . join ( path , name ) ;
162+ }
163+
164+ if ( isUint8Array ( path ) && isUint8Array ( name ) ) {
165+ return Buffer . concat ( [ path , bufferSep , name ] ) ;
166+ }
167+
168+ throw new ERR_INVALID_ARG_TYPE (
169+ 'path' , [ 'string' , 'Buffer' ] , path ) ;
170+ }
171+
147172function getDirents ( path , [ names , types ] , callback ) {
148173 let i ;
149174 if ( typeof callback === 'function' ) {
@@ -156,7 +181,14 @@ function getDirents(path, [names, types], callback) {
156181 const name = names [ i ] ;
157182 const idx = i ;
158183 toFinish ++ ;
159- lazyLoadFs ( ) . lstat ( pathModule . join ( path , name ) , ( err , stats ) => {
184+ let filepath ;
185+ try {
186+ filepath = join ( path , name ) ;
187+ } catch ( err ) {
188+ callback ( err ) ;
189+ return ;
190+ }
191+ lazyLoadFs ( ) . lstat ( filepath , ( err , stats ) => {
160192 if ( err ) {
161193 callback ( err ) ;
162194 return ;
@@ -185,7 +217,14 @@ function getDirents(path, [names, types], callback) {
185217function getDirent ( path , name , type , callback ) {
186218 if ( typeof callback === 'function' ) {
187219 if ( type === UV_DIRENT_UNKNOWN ) {
188- lazyLoadFs ( ) . lstat ( pathModule . join ( path , name ) , ( err , stats ) => {
220+ let filepath ;
221+ try {
222+ filepath = join ( path , name ) ;
223+ } catch ( err ) {
224+ callback ( err ) ;
225+ return ;
226+ }
227+ lazyLoadFs ( ) . lstat ( filepath , ( err , stats ) => {
189228 if ( err ) {
190229 callback ( err ) ;
191230 return ;
@@ -196,7 +235,7 @@ function getDirent(path, name, type, callback) {
196235 callback ( null , new Dirent ( name , type ) ) ;
197236 }
198237 } else if ( type === UV_DIRENT_UNKNOWN ) {
199- const stats = lazyLoadFs ( ) . lstatSync ( pathModule . join ( path , name ) ) ;
238+ const stats = lazyLoadFs ( ) . lstatSync ( join ( path , name ) ) ;
200239 return new DirentFromStats ( name , stats ) ;
201240 } else {
202241 return new Dirent ( name , type ) ;
0 commit comments