Skip to content

Commit c774e0a

Browse files
committed
Fix bugs to pass Ruby unit tests
1 parent 933186d commit c774e0a

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

npm_and_yarn/helpers/lib/npm/vulnerability-auditor.js

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -227,29 +227,21 @@ function groupBy(elems, fn) {
227227
* ArboristNode.location and will be of the form "node_modules/foo/node_modules/bar".
228228
*/
229229
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
233238
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
250242
}
251243
}
252-
return current;
244+
return current
253245
}
254246

255247
async function loadNpmConfig() {

0 commit comments

Comments
 (0)