File tree Expand file tree Collapse file tree 1 file changed +12
-20
lines changed
npm_and_yarn/helpers/lib/npm Expand file tree Collapse file tree 1 file changed +12
-20
lines changed Original file line number Diff line number Diff line change @@ -227,29 +227,21 @@ function groupBy(elems, fn) {
227
227
* ArboristNode.location and will be of the form "node_modules/foo/node_modules/bar".
228
228
*/
229
229
function lookupChildLocation ( root , location ) {
230
- const parts = location . split ( '/' ) ;
231
- let current = root ;
232
- let state = '' ;
230
+ if ( ! location . startsWith ( 'node_modules/' ) ) {
231
+ // The location must start with 'node_modules/' to be valid.
232
+ return null ;
233
+ }
234
+ const parts = location
235
+ . substring ( 'node_modules/' . length )
236
+ . split ( '/node_modules/' )
237
+ let current = root
233
238
for ( const part of parts ) {
234
- if ( state == '' ) {
235
- if ( part === 'node_modules' ) {
236
- state = 'node_modules' ;
237
- } else {
238
- // Unexpected part
239
- return null ;
240
- }
241
- } else if ( state === 'node_modules' ) {
242
- state = '' ;
243
- current = current . children . get ( part ) ;
244
- if ( ! current ) {
245
- return null ;
246
- }
247
- } else {
248
- // Unexpected state
249
- return null ;
239
+ current = current . children . get ( part )
240
+ if ( ! current ) {
241
+ return null
250
242
}
251
243
}
252
- return current ;
244
+ return current
253
245
}
254
246
255
247
async function loadNpmConfig ( ) {
You can’t perform that action at this time.
0 commit comments