Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Only subset of shell functionality is supported #430

Open
graywolf-at-work opened this issue Apr 15, 2021 · 2 comments
Open

Only subset of shell functionality is supported #430

graywolf-at-work opened this issue Apr 15, 2021 · 2 comments

Comments

@graywolf-at-work
Copy link

Steps to reproduce

I've run into an issue today, when under impression that dotenv (since it
states that the file can be sources into shell) supports basically POSIX shell.
However, that was actually not so. Main issue is not necessarily the lack of the
functionality (it is and I had to stop using dotenv in our CI), but that the
unsupported syntax is just silently ignored.

+$ ls
env  Gemfile  Gemfile.lock  test.rb  test.sh
+$ cat env
X=${Y-Z}
export X
+$ env | grep ^Y=
+$ cat Gemfile
source 'https://rubygems.org' do
  gem 'dotenv'
end
+$ cat Gemfile.lock
GEM
  specs:

GEM
  remote: https://rubygems.org/
  specs:
    dotenv (2.7.6)

PLATFORMS
  x86_64-linux

DEPENDENCIES
  dotenv!

BUNDLED WITH
   2.2.16
+$ cat test.rb
#!/usr/bin/env ruby
# frozen_string_literal: true
$-v = true

require('dotenv')
Dotenv.load('env')

pp(ENV['X'])
+$ cat test.sh
#!/bin/sh

. ./env

echo $X
+$ bundle exec ./test.rb
"-Z}"
+$ ./test.sh
Z

Assuming we would be willing to invoke actual shell, I believe it is possible to
support full POSIX range of features. Assuming that would be accepted, I'm
willing to work on such addition. Would it be merged?

Expected behavior

+$ bundle exec ./test.rb
"Z"

Actual behavior

+$ bundle exec ./test.rb
"-Z}"

System configuration

dotenv version:

2.7.6

Rails version:

N/A

Ruby version:

2.7.2

@bkeepers
Copy link
Owner

@graywolf-at-work thanks for reporting the issue. You're right that dotenv only supports a subset of POSIX shell functionality. Most of it has been added over time as people needed different features. It is definitely a bug that unsupported syntax is silently ignored.

I would gladly consider a PR that invokes shell, as long as the current tests continue to pass, and it can be implemented in a way that is supported across all platforms (or at least falls back to current implementation on unsupported platforms).

@graywolf-at-work
Copy link
Author

I've got ack from my management so I'll will try to look into this next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants