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

Exporting .env files does not behave same as loading file in Vapor with regard to empty strings #110

Open
tomjoro opened this issue Jan 21, 2021 · 0 comments

Comments

@tomjoro
Copy link

tomjoro commented Jan 21, 2021

When a setting is exported from a .env file empty strings will appear in environment like this:

.env
SOME_SETTING=

Running:
export $(xargs < config/environments/.env)

Will set in environment:
SOME_SETTING=''

Now if you try to load this .env with Vapor the setting SOME_SETTING will not be set at all. Some configurations, e.g. RabbitMQ treat an empty string as a request to autogenerate so we must use an empty string for the setting.

The solution I propose is to detect empty string values and then set it. This change in Vapor.Provider.Dotenv would be this:

defp parse_pair([key, value], acc) do
    cond do
      String.length(key) > 0 && String.length(value) > 0 ->
        key = String.trim(key)
        value = String.trim(value)

        case starting_heredoc(value) do
          [_, delimiter] -> {key, delimiter, [], acc}
          _ -> [{key, value} | acc]
        end
      String.length(key) > 0 && String.length(value) == 0 ->
        key = String.trim(key)
        value = ""
        [{key, value} | acc]
      true ->
        acc
    end
  end

This fix is working for us.

I can generate a pull request but wanted to verify with you if this is correct?

Great project, thanks!

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

1 participant