dotenv icon indicating copy to clipboard operation
dotenv copied to clipboard

Supporting Escape Sequences

Open bd82 opened this issue 1 year ago • 1 comments

Hello @motdotla and thank you for creating dotenv nodejs library 👍

Feature Request

Could dotenv nodejs library support escape sequences (e.g \" \t) ?

At the minimum can it be aligned with the Ruby dotenv library?

  • version 2.8.0 added https://github.com/bkeepers/dotenv/pull/421

Would a PR which aligns with the Ruby library be welcome?

Context

I've noticed some implementations of dotenv support character escapes and some do not. Also there does not seem to be an official specification anywhere for dotenv. This is causing issues when we need to use the same .env files in multiple runtimes.

Is the Ruby library the original implementation and thus also used as the pseudo specification?

Examples of escape handling in different dotenv libraries

Ruby Library

  • Supports escaping anything other than $
  • Only interpret values of \n and \r and only in double quoted strings.
  • Relevant Source Code

Elixir Library escaping specs

  • Seems to allow expanding of more special sequences versus the Ruby library, e.g: \t and \f
  • Does not seem to distinguish (at the spec level at least) between single or double quotes escape values.

Python Library

  •    Allowed escape sequences:
    
      in single-quoted values: \\, \'
      in double-quoted values: \\, \', \", \a, \b, \f, \n, \r, \t, \v
    

bd82 avatar Jan 26 '23 14:01 bd82