avdi/dotenv_elixir — pull request #15 by alxndr (2014-12-13 02:42:49+00:00)
Title: ignore whitespace separating value and inline comment

This adds support for a having `#` comment which is made inline, separated from a variable's value by whitespace.

Use case: I'm fond of quickly testing environment changes by modifying the value but keeping the original as a comment at the end of the same line. For example, my .env file might start off like this:

THIRD_PARTY_HOST=some.thirdparty.co.gov

...but to get it to point to my own local version of that service, I'd modify it to look like this:

THIRD_PARTY_HOST=localhost:4000 # some.thirdparty.co.gov

When I tried this in a project using dotenv_elixir, I found that the above `THIRD_PARTY_HOST` would have this as the value: "localhost:4000 " — note the space after the last 0.

This commit makes the "unquoted value" matcher non-greedy, so that the `\s*` in the trailing "optional comment" section of the regex picks up any trailing whitespace.