Skip to content

Commit 49a4eef

Browse files
authored
fix: use look behind regex for trailing slash stripping (#8676)
In context this isn't a big deal, the extra slash is usually an artifact of path and url parsing. Linting will not warn about this now though.
1 parent 679486b commit 49a4eef

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/commands/explain.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ class Explain extends ArboristWorkspaceCmd {
9292
}
9393

9494
// if it's a location, get that node
95-
const maybeLoc = arg.replace(/\\/g, '/').replace(/\/+$/, '')
95+
const maybeLoc = arg.replace(/\\/g, '/').replace(/(?<!\/)\/+$/, '')
9696
const nodeByLoc = tree.inventory.get(maybeLoc)
9797
if (nodeByLoc) {
9898
return [nodeByLoc]
9999
}
100100

101101
// maybe a path to a node_modules folder
102102
const maybePath = relative(this.npm.prefix, resolve(maybeLoc))
103-
.replace(/\\/g, '/').replace(/\/+$/, '')
103+
.replace(/\\/g, '/').replace(/(?<!\/)\/+$/, '')
104104
const nodeByPath = tree.inventory.get(maybePath)
105105
if (nodeByPath) {
106106
return [nodeByPath]

workspaces/arborist/lib/arborist/build-ideal-tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ module.exports = cls => class IdealTreeBuilder extends cls {
103103

104104
// normalize trailing slash
105105
const registry = options.registry || 'https://registry.npmjs.org'
106-
options.registry = this.registry = registry.replace(/\/+$/, '') + '/'
106+
options.registry = this.registry = registry.replace(/(?<!\/)\/+$/, '') + '/'
107107

108108
const {
109109
follow = false,

0 commit comments

Comments
 (0)