@@ -193,7 +193,7 @@ const transliterate = str =>
193193// converting the path to UTF-8 is not necessary in JS as it's the default
194194const normalize = path => {
195195 // Remove any characters with byte value of 0
196- let cleaned = ( path || '' ) . replace ( / \0 / g, '' )
196+ let cleaned = ( typeof path === 'string' ? path : '' ) . replace ( / \0 / g, '' )
197197
198198 // Convert any backslash (\) characters to a forward slash (/)
199199 cleaned = cleaned . replace ( / \\ / g, '/' )
@@ -237,20 +237,21 @@ const normalizeForComparison = path => {
237237 return normalized
238238}
239239
240- const same = ( path1 , path2 ) =>
241- normalizeForComparison ( path1 ) === normalizeForComparison ( path2 )
240+ const same = ( path1 , path2 ) => typeof path1 === 'string' && typeof path2 === 'string'
241+ && normalizeForComparison ( path1 ) === normalizeForComparison ( path2 )
242242
243- const startsWith = ( path1 , path2 ) =>
244- normalizeForComparison ( path1 ) . startsWith ( normalizeForComparison ( path2 ) )
243+ const startsWith = ( path1 , path2 ) => typeof path1 === 'string' && typeof path2 === 'string'
244+ && normalizeForComparison ( path1 ) . startsWith ( normalizeForComparison ( path2 ) )
245245
246246const keyLookup = ( object , path ) => {
247- const key = Object . keys ( object ) . find ( key => same ( key , path ) )
247+ const key = Object . keys ( object || { } ) . find ( key => same ( key , path ) )
248248 return typeof key === 'string' ? object [ key ] : undefined
249249}
250250
251251const pathNormalizer = {
252252 keyLookup,
253253 normalize,
254+ normalizeForComparison,
254255 same,
255256 startsWith,
256257}
0 commit comments