Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Environment-name to DOTENV_PRIVATE_KEY_* convention is not reversible (dotted vs underscored filenames collide)

Aperta
#951 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
cli

Direzione di ricerca

Inizia da src/lib/conventions/environment.js e src/lib/helpers/guessPrivateKeyFilename.js, quindi segui il loro utilizzo attraverso src/lib/helpers/envResolution/determine.js. Riproduci la collisione con .env.ci_test e .env.ci.test e aggiungi una copertura di regressione che dimostri che la ricerca implicita gestisce entrambe le forme valide del nome file senza selezionare il file errato né segnalare un file mancante.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

The convention that maps an env filename to its DOTENV_PRIVATE_KEY_* variable name (src/lib/conventions/environment.js) and the reverse mapping used for implicit file discovery (src/lib/helpers/guessPrivateKeyFilename.js) are not inverses of each other. Different, both-valid filenames collapse onto the same key name, so the reverse guess is ambiguous/wrong whenever an environment segment itself contains an underscore.

Where

environment.js joins multi-part (dot-separated) environment segments with _ when building the key suffix:

if (possibleEnvironmentList.length === 2) {
  return possibleEnvironmentList.join('_')
}

guessPrivateKeyFilename.js always reverses an underscore back into a dot:

const filenameSuffix = privateKeyName.substring(`${PREFIX}_`.length).split('_').join('.').toLowerCase()

This is used by src/lib/helpers/envResolution/determine.js, which is the code path taken whenever a user relies on the documented implicit/zero-config convention (no -f flag, just DOTENV_PRIVATE_KEY_* set, e.g. in CI secrets).

Repro
const keynames = require('./src/lib/conventions/keynames')

keynames('.env.ci_test').privateKeyName   // -> DOTENV_PRIVATE_KEY_CI_TEST
keynames('.env.ci.test').privateKeyName   // -> DOTENV_PRIVATE_KEY_CI_TEST  (same!)

Both .env.ci_test (single-word environment name, underscore) and .env.ci.test (two dot-separated segments) produce the identical key name DOTENV_PRIVATE_KEY_CI_TEST. But guessPrivateKeyFilename('DOTENV_PRIVATE_KEY_CI_TEST') always returns .env.ci.test.

So a project that names its file .env.ci_test and sets DOTENV_PRIVATE_KEY_CI_TEST (following dotenvx's own convention, no -f flag) will have dotenvx run go looking for .env.ci.test, a file that doesn't exist, and fail with a missing-env-file error, even though the correctly named file and matching key are both present.

Same collision applies more generally, e.g. .env.staging.local and .env.staging_local both map to DOTENV_PRIVATE_KEY_STAGING_LOCAL.

Suggested fix

Either disallow/escape underscores in environment segments when building the key name (so the mapping is bijective), or have determine() try both the dotted and underscored candidate filenames before giving up.

cc @motdotla, this affects the core zero-config file-discovery convention, so wanted to flag it directly.

Lingua principale
JavaScript
Stelle
5.8k
Fork
166
Merge medio
4h 20m
PR unite (30g)
35

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di dotenvx/dotenvx

Tutte le issue di dotenvx/dotenvx

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.