motdotla / dotenv-expand

Variable expansion for dotenv. Expand variables already on your machine for use in your .env file.
https://dotenvx.com
BSD 2-Clause "Simplified" License
953 stars 95 forks source link

Allow to use env variables with '.' in it's name (i.e. REDIS.PUBSUB.PORT) #84

Closed flamewow closed 9 months ago

flamewow commented 2 years ago

currently, if I want to use a variable whose name contains "." (e.g. REDIS.PUBSUB.PORT) the lib is not working.

Should be as simple as changing regex to allow "."

  const matches = envValue.match(/(.?\${*[\w\.]*(?::-[\w/]*)?}*)/g) || []

  return matches.reduce(function (newEnv, match, index) {
    const parts = /(.?)\${*([\w\.]*(?::-[\w/]*)?)?}*/g.exec(match)
    if (!parts || parts.length === 0) {
      return newEnv
    }
flamewow commented 1 year ago

the PR https://github.com/motdotla/dotenv-expand/pull/93

motdotla commented 9 months ago

our position on variable names is:

For the sake of portability (and sanity), environment variable names must consist solely of letters, digits, and the underscore ( _ ) and must not begin with a digit. In regex-speak, the names must match the following pattern:

https://dotenvx.com/docs/env-file#variable-names

that said, i would like to hear from people who simply do not have control over these env variable names. if so, what service is setting them like that for you? i've never seen that before in the many hosting, db, and other 3rd party services I've used.