diff --git a/CHANGELOG.md b/CHANGELOG.md index e7be24d421..6842713946 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ Please add one entry in this file for each change in Yarn's behavior. Use the sa ## Master +- Fixes `npm_config_` environment variable parsing to support those prefixed with underscore (ex: `_auth`) + + [#7070](https://github.com/yarnpkg/yarn/pull/7070) - [**Nicholas Boll**](https://github.com/NicholasBoll) + - Fixes yarn `upgrade --latest` for dependencies using `>` or `>=` range specifier [#7080](https://github.com/yarnpkg/yarn/pull/7080) - [**Xukai Wu**](https://github.com/shilcare) diff --git a/__tests__/registries/npm-registry.js b/__tests__/registries/npm-registry.js index 4848cef2db..b5177b7719 100644 --- a/__tests__/registries/npm-registry.js +++ b/__tests__/registries/npm-registry.js @@ -731,6 +731,37 @@ describe('isScopedPackage functional test', () => { }); }); +describe('environment variables functional test', () => { + beforeEach(() => { + process.env.npm_config_always_auth = 'true'; + process.env.npm_config__auth = 'auth'; + process.env.npm_config__authtoken = 'authToken'; + process.env.npm_config__username = 'username'; + process.env.npm_config__password = 'password'; + }); + + afterEach(() => { + delete process.env.npm_config_always_auth; + delete process.env.npm_config__auth; + delete process.env.npm_config__authToken; + delete process.env.npm_config__username; + delete process.env.npm_config__password; + }); + + test('correctly escapes environment config variables', () => { + const testCwd = '.'; + const {mockRequestManager, mockRegistries, mockReporter} = createMocks(); + const npmRegistry = new NpmRegistry(testCwd, mockRegistries, mockRequestManager, mockReporter, true, []); + + npmRegistry.mergeEnv('npm_config_'); + expect(npmRegistry.config).toHaveProperty('always-auth', true); + expect(npmRegistry.config).toHaveProperty('_auth', 'auth'); + expect(npmRegistry.config).toHaveProperty('_authtoken', 'authToken'); + expect(npmRegistry.config).toHaveProperty('_username', 'username'); + expect(npmRegistry.config).toHaveProperty('_password', 'password'); + }); +}); + describe('getRequestUrl functional test', () => { test('returns pathname when it is a full URL', () => { const testCwd = '.'; diff --git a/src/registries/base-registry.js b/src/registries/base-registry.js index c563a7edfd..342362abcb 100644 --- a/src/registries/base-registry.js +++ b/src/registries/base-registry.js @@ -170,8 +170,8 @@ export default class BaseRegistry { // replace dunders with dots key = key.replace(/__/g, '.'); - // replace underscores with dashes - key = key.replace(/_/g, '-'); + // replace underscores with dashes ignoring keys that start with an underscore + key = key.replace(/([^_])_/g, '$1-'); // set it via a path objectPath.set(this.config, key, val);