Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG] npm config set ignores values starting with "-" #5131

Closed
2 tasks done
Ansile opened this issue Jul 7, 2022 · 1 comment
Closed
2 tasks done

[BUG] npm config set ignores values starting with "-" #5131

Ansile opened this issue Jul 7, 2022 · 1 comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release

Comments

@Ansile
Copy link

Ansile commented Jul 7, 2022

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

When npm config set is provided with value that starts with "-", it ignores this value and sets an empty string instead.
This is a serious issue for us, as some tokens can generate starting with "-".

Bug case:

y-golubev:~ y.golubev$ npm -v
8.5.5

y-golubev:~ y.golubev$ npm config set "foo" "-bar"

y-golubev:~ y.golubev$ npm config list
...
foo = ""

Expected Behavior

Instead, it should just set the provided value.

Expected:

y-golubev:~ y.golubev$ npm -v
8.5.5

y-golubev:~ y.golubev$ npm config set "foo" "-bar"

y-golubev:~ y.golubev$ npm config list
...
foo = "-bar" 

That's the way it works with all other values.

Steps To Reproduce

Works the same with basically any npm version.

Run:

npm config set "foo" "-bar"
npm config list | grep foo

Outputs foo = ""

Environment

  • npm: 8.5.5
  • Node.js: v17.8.0
  • OS Name: macOS 10.14.6
  • System Model Name: Macbook Pro
@Ansile Ansile added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Jul 7, 2022
@nlf
Copy link
Contributor

nlf commented Jul 13, 2022

this is due to our cli's options parser eating -bar as though it were a flag. to get around this, you can tell the parser you're explicitly done with flags by adding -- to your command. anything that comes after the -- will not be parsed and will correctly show up as a positional argument internally.

> npm config set -- foo -bar
> npm config get foo
-bar

feel free to reopen this issue if that doesn't work for you

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

2 participants