Skip to content

[BUG] bin doesnt work when incrementing arg with equals sign #431

Closed
@gonza7aav

Description

@gonza7aav

What / Why

Why it unshift an empty string into argv when an argument contains a "="?

// line 35 @ /bin/semver.js
let a = argv.shift()
const indexOfEqualSign = a.indexOf('=')
if (indexOfEqualSign !== -1) {
  a = a.slice(0, indexOfEqualSign)
  argv.unshift(a.slice(indexOfEqualSign + 1))
}

Let's suppose a contains an "=", then indexOfEqualSign won't be -1. Inside the if statement, it overwrites a with a slice of it (removing whatever is after the "="). After that, it inserts into argv another slice of a. But this slice starts at indexOfEqualSign + 1 (the part we just remove), so an empty string ("") will be returned by the slice and inserted by the unshift.

As I understood, the empty string doesn't affect the execution because it is filtered out at line 92. But, Why it bother to add an "", loop with it, add it to versions to finally remove from versions? I think I am missing something. Can someone explain it to me, please?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions