dotenv 3.1.2 → 3.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/lib/dotenv/parser.rb +54 -59
- data/lib/dotenv/rails.rb +3 -6
- data/lib/dotenv/substitutions/command.rb +1 -1
- data/lib/dotenv/substitutions/variable.rb +9 -15
- data/lib/dotenv/template.rb +1 -1
- data/lib/dotenv/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a4ad122f937755147ff0cc52552f17b1e1cf8f9a290ff791ac5ba2f8ef8b43c7
|
4
|
+
data.tar.gz: 3116d767ea5dc67adca867395ea7effbc1b4ee30769223961f8d041d5c34482d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86436a8b6d193590befeb48a29882b9bd5523f8b80fff961faf1feda91cc720b8b44c1e2705bfbebb73836b99684273d49f78b94c09d05a3077e62996473a47c
|
7
|
+
data.tar.gz: bb6f98a159c821e0f1cb98ab6c3f0b54a109acc3c934770fd6603f7497c047f031c7124f839963f0f5132a12bd2736e25ab2e4c648cfa56589a30b328d03de61
|
data/README.md
CHANGED
@@ -180,7 +180,7 @@ end
|
|
180
180
|
Available options:
|
181
181
|
|
182
182
|
* `Dotenv::Rails.files` - list of files to be loaded, in order of precedence.
|
183
|
-
* `Dotenv::Rails.overwrite` - Overwrite
|
183
|
+
* `Dotenv::Rails.overwrite` - Overwrite existing `ENV` variables with contents of `.env*` files
|
184
184
|
* `Dotenv::Rails.logger` - The logger to use for dotenv's logging. Defaults to `Rails.logger`
|
185
185
|
* `Dotenv::Rails.autorestore` - Enable or disable [autorestore](#autorestore-in-tests)
|
186
186
|
|
@@ -213,7 +213,7 @@ DATABASE_URL="postgres://$(whoami)@localhost/my_database"
|
|
213
213
|
|
214
214
|
### Variable Substitution
|
215
215
|
|
216
|
-
You need to add the value of another variable in one of your variables? You can reference the variable with `${VAR}` or often just `$VAR` in
|
216
|
+
You need to add the value of another variable in one of your variables? You can reference the variable with `${VAR}` or often just `$VAR` in unquoted or double-quoted values.
|
217
217
|
|
218
218
|
```shell
|
219
219
|
DATABASE_URL="postgres://${USER}@localhost/my_database"
|
@@ -276,7 +276,7 @@ You can use the `-t` or `--template` flag on the dotenv cli to create a template
|
|
276
276
|
```console
|
277
277
|
$ dotenv -t .env
|
278
278
|
```
|
279
|
-
A template will be created in your working directory named `{
|
279
|
+
A template will be created in your working directory named `{FILENAME}.template`. So in the above example, it would create a `.env.template` file.
|
280
280
|
|
281
281
|
The template will contain all the environment variables in your `.env` file but with their values set to the variable names.
|
282
282
|
|
data/lib/dotenv/parser.rb
CHANGED
@@ -8,25 +8,29 @@ module Dotenv
|
|
8
8
|
# Parses the `.env` file format into key/value pairs.
|
9
9
|
# It allows for variable substitutions, command substitutions, and exporting of variables.
|
10
10
|
class Parser
|
11
|
-
@substitutions =
|
12
|
-
|
11
|
+
@substitutions = [
|
12
|
+
Dotenv::Substitutions::Variable,
|
13
|
+
Dotenv::Substitutions::Command
|
14
|
+
]
|
13
15
|
|
14
16
|
LINE = /
|
15
|
-
(?:^|\A)
|
16
|
-
\s*
|
17
|
-
(
|
18
|
-
([\w.]+)
|
19
|
-
(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
(?:^|\A) # beginning of line
|
18
|
+
\s* # leading whitespace
|
19
|
+
(?<export>export\s+)? # optional export
|
20
|
+
(?<key>[\w.]+) # key
|
21
|
+
(?: # optional separator and value
|
22
|
+
(?:\s*=\s*?|:\s+?) # separator
|
23
|
+
(?<value> # optional value begin
|
24
|
+
\s*'(?:\\'|[^'])*' # single quoted value
|
25
|
+
| # or
|
26
|
+
\s*"(?:\\"|[^"])*" # double quoted value
|
27
|
+
| # or
|
28
|
+
[^\#\n]+ # unquoted value
|
29
|
+
)? # value end
|
30
|
+
)? # separator and value end
|
31
|
+
\s* # trailing whitespace
|
32
|
+
(?:\#.*)? # optional comment
|
33
|
+
(?:$|\z) # end of line
|
30
34
|
/x
|
31
35
|
|
32
36
|
class << self
|
@@ -38,41 +42,55 @@ module Dotenv
|
|
38
42
|
end
|
39
43
|
|
40
44
|
def initialize(string, overwrite: false)
|
41
|
-
|
45
|
+
# Convert line breaks to same format
|
46
|
+
@string = string.gsub(/\r\n?/, "\n")
|
42
47
|
@hash = {}
|
43
48
|
@overwrite = overwrite
|
44
49
|
end
|
45
50
|
|
46
51
|
def call
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
52
|
+
@string.scan(LINE) do
|
53
|
+
match = $LAST_MATCH_INFO
|
54
|
+
|
55
|
+
if existing?(match[:key])
|
56
|
+
# Use value from already defined variable
|
57
|
+
@hash[match[:key]] = ENV[match[:key]]
|
58
|
+
elsif match[:export] && !match[:value]
|
59
|
+
# Check for exported variable with no value
|
60
|
+
if !@hash.member?(match[:key])
|
61
|
+
raise FormatError, "Line #{match.to_s.inspect} has an unset variable"
|
62
|
+
end
|
63
|
+
else
|
64
|
+
@hash[match[:key]] = parse_value(match[:value] || "")
|
65
|
+
end
|
56
66
|
end
|
67
|
+
|
57
68
|
@hash
|
58
69
|
end
|
59
70
|
|
60
71
|
private
|
61
72
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
raise FormatError, "Line #{line.inspect} has an unset variable"
|
66
|
-
end
|
67
|
-
end
|
73
|
+
# Determine if a variable is already defined and should not be overwritten.
|
74
|
+
def existing?(key)
|
75
|
+
!@overwrite && key != "DOTENV_LINEBREAK_MODE" && ENV.key?(key)
|
68
76
|
end
|
69
77
|
|
78
|
+
QUOTED_STRING = /\A(['"])(.*)\1\z/m
|
70
79
|
def parse_value(value)
|
71
80
|
# Remove surrounding quotes
|
72
|
-
value = value.strip.sub(
|
81
|
+
value = value.strip.sub(QUOTED_STRING, '\2')
|
73
82
|
maybe_quote = Regexp.last_match(1)
|
74
|
-
|
75
|
-
|
83
|
+
|
84
|
+
# Expand new lines in double quoted values
|
85
|
+
value = expand_newlines(value) if maybe_quote == '"'
|
86
|
+
|
87
|
+
# Unescape characters and performs substitutions unless value is single quoted
|
88
|
+
if maybe_quote != "'"
|
89
|
+
value = unescape_characters(value)
|
90
|
+
self.class.substitutions.each { |proc| value = proc.call(value, @hash) }
|
91
|
+
end
|
92
|
+
|
93
|
+
value
|
76
94
|
end
|
77
95
|
|
78
96
|
def unescape_characters(value)
|
@@ -86,28 +104,5 @@ module Dotenv
|
|
86
104
|
value.gsub('\n', "\\\\\\n").gsub('\r', "\\\\\\r")
|
87
105
|
end
|
88
106
|
end
|
89
|
-
|
90
|
-
def variable_not_set?(line)
|
91
|
-
!line.split[1..].all? { |var| @hash.member?(var) }
|
92
|
-
end
|
93
|
-
|
94
|
-
def unescape_value(value, maybe_quote)
|
95
|
-
if maybe_quote == '"'
|
96
|
-
unescape_characters(expand_newlines(value))
|
97
|
-
elsif maybe_quote.nil?
|
98
|
-
unescape_characters(value)
|
99
|
-
else
|
100
|
-
value
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def perform_substitutions(value, maybe_quote)
|
105
|
-
if maybe_quote != "'"
|
106
|
-
self.class.substitutions.each do |proc|
|
107
|
-
value = proc.call(value, @hash, overwrite: @overwrite)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
value
|
111
|
-
end
|
112
107
|
end
|
113
108
|
end
|
data/lib/dotenv/rails.rb
CHANGED
@@ -10,14 +10,11 @@ require "dotenv/log_subscriber"
|
|
10
10
|
Dotenv.instrumenter = ActiveSupport::Notifications
|
11
11
|
|
12
12
|
# Watch all loaded env files with Spring
|
13
|
-
|
14
|
-
|
15
|
-
ActiveSupport::Notifications.subscribe("load.dotenv") do |*args|
|
13
|
+
ActiveSupport::Notifications.subscribe("load.dotenv") do |*args|
|
14
|
+
if defined?(Spring) && Spring.respond_to?(:watch)
|
16
15
|
event = ActiveSupport::Notifications::Event.new(*args)
|
17
16
|
Spring.watch event.payload[:env].filename if Rails.application
|
18
17
|
end
|
19
|
-
rescue LoadError, ArgumentError
|
20
|
-
# Spring is not available
|
21
18
|
end
|
22
19
|
|
23
20
|
module Dotenv
|
@@ -26,7 +23,7 @@ module Dotenv
|
|
26
23
|
delegate :files, :files=, :overwrite, :overwrite=, :autorestore, :autorestore=, :logger, to: "config.dotenv"
|
27
24
|
|
28
25
|
def initialize
|
29
|
-
super
|
26
|
+
super
|
30
27
|
config.dotenv = ActiveSupport::OrderedOptions.new.update(
|
31
28
|
# Rails.logger is not available yet, so we'll save log messages and replay them when it is
|
32
29
|
logger: Dotenv::ReplayLogger.new,
|
@@ -12,29 +12,23 @@ module Dotenv
|
|
12
12
|
VARIABLE = /
|
13
13
|
(\\)? # is it escaped with a backslash?
|
14
14
|
(\$) # literal $
|
15
|
-
(?!\() #
|
15
|
+
(?!\() # shouldn't be followed by parenthesis
|
16
16
|
\{? # allow brace wrapping
|
17
17
|
([A-Z0-9_]+)? # optional alpha nums
|
18
18
|
\}? # closing brace
|
19
19
|
/xi
|
20
20
|
|
21
|
-
def call(value, env
|
22
|
-
combined_env = overwrite ? ENV.to_h.merge(env) : env.merge(ENV)
|
21
|
+
def call(value, env)
|
23
22
|
value.gsub(VARIABLE) do |variable|
|
24
23
|
match = $LAST_MATCH_INFO
|
25
|
-
substitute(match, variable, combined_env)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
24
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
25
|
+
if match[1] == "\\"
|
26
|
+
variable[1..]
|
27
|
+
elsif match[3]
|
28
|
+
env[match[3]] || ENV[match[3]] || ""
|
29
|
+
else
|
30
|
+
variable
|
31
|
+
end
|
38
32
|
end
|
39
33
|
end
|
40
34
|
end
|
data/lib/dotenv/template.rb
CHANGED
data/lib/dotenv/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotenv
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -83,8 +83,9 @@ files:
|
|
83
83
|
homepage: https://github.com/bkeepers/dotenv
|
84
84
|
licenses:
|
85
85
|
- MIT
|
86
|
-
metadata:
|
87
|
-
|
86
|
+
metadata:
|
87
|
+
changelog_uri: https://github.com/bkeepers/dotenv/releases
|
88
|
+
post_install_message:
|
88
89
|
rdoc_options: []
|
89
90
|
require_paths:
|
90
91
|
- lib
|
@@ -99,8 +100,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
100
|
- !ruby/object:Gem::Version
|
100
101
|
version: '0'
|
101
102
|
requirements: []
|
102
|
-
rubygems_version: 3.5.
|
103
|
-
signing_key:
|
103
|
+
rubygems_version: 3.5.22
|
104
|
+
signing_key:
|
104
105
|
specification_version: 4
|
105
106
|
summary: Loads environment variables from `.env`.
|
106
107
|
test_files: []
|