dotenv 2.4.0 → 2.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0e18e29270d6ef436918824cab86453fba5143c8
4
- data.tar.gz: 2303f9975ba1738ebafc3d0baea4f4abd785e558
3
+ metadata.gz: 2e64cd0a67971ea4a843e624a6362e89b623697c
4
+ data.tar.gz: 7dd0bbd8488f581d5dbf1f4bfcdc5c3e97bdf623
5
5
  SHA512:
6
- metadata.gz: ec8c2d505f5e77a9d9f638b3f4287c3fcf8de7e6d572d3d70102dea2638219f3184ab631f6c7ce0b1925633b239ddf91a9d788eff39bc90e62e546fcb894210a
7
- data.tar.gz: ebeaa07575e7a0026bd17edbea7cf2b83773548cdff59c3b603eda1538b52e9228720ee2d94619d193c0a08b9cb7128bb81b46bda9bede7f30c857b47eef95f5
6
+ metadata.gz: e7e8fcbb2f35999a5e3ccf1d6f37b97aa6d21ddffbb59235cad590b15d1e9e74356da50174393de20cde97395046fe4f48edf8a5aec59d5901117c21cb94f953
7
+ data.tar.gz: fed27a558c70aa6d7b0f435f16b437c0be83a60c1525c6afe89add406e68ec94c3ebdffbc6698c3ae8952ce1cab576c2bab683e11e68ca2f40c5d16778ab2c97
data/README.md CHANGED
@@ -116,9 +116,21 @@ export SECRET_KEY=YOURSECRETKEYGOESHERE
116
116
  If you need multiline variables, for example private keys, you can double quote strings and use the `\n` character for newlines:
117
117
 
118
118
  ```shell
119
- PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nHkVN9…\n-----END DSA PRIVATE KEY-----\n"
119
+ PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nHkVN9...\n-----END DSA PRIVATE KEY-----\n"
120
120
  ```
121
121
 
122
+ Alternatively, multi-line values with line breaks are now supported for quoted values.
123
+
124
+ ```shell
125
+ PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
126
+ ...
127
+ HkVN9...
128
+ ...
129
+ -----END DSA PRIVATE KEY-----"
130
+ ```
131
+
132
+ This is particularly helpful when using the Heroku command line plugin [`heroku-config`](https://github.com/xavdid/heroku-config) to pull configuration variables down that may have line breaks.
133
+
122
134
  ### Command Substitution
123
135
 
124
136
  You need to add the output of a command in one of your variables? Simply add it with `$(your_command)`:
@@ -4,12 +4,12 @@ module Dotenv
4
4
  class Environment < Hash
5
5
  attr_reader :filename
6
6
 
7
- def initialize(filename, is_load)
7
+ def initialize(filename, is_load = false)
8
8
  @filename = filename
9
9
  load(is_load)
10
10
  end
11
11
 
12
- def load(is_load)
12
+ def load(is_load = false)
13
13
  update Parser.call(read, is_load)
14
14
  end
15
15
 
@@ -12,21 +12,21 @@ module Dotenv
12
12
  [Dotenv::Substitutions::Variable, Dotenv::Substitutions::Command]
13
13
 
14
14
  LINE = /
15
- \A
16
- \s*
17
- (?:export\s+)? # optional export
18
- ([\w\.]+) # key
19
- (?:\s*=\s*|:\s+?) # separator
20
- ( # optional value begin
21
- '(?:\'|[^'])*' # single quoted value
22
- | # or
23
- "(?:\"|[^"])*" # double quoted value
24
- | # or
25
- [^#\n]+ # unquoted value
26
- )? # value end
27
- \s*
28
- (?:\#.*)? # optional comment
29
- \z
15
+ (?:^|\A) # beginning of line
16
+ \s* # leading whitespace
17
+ (?:export\s+)? # optional export
18
+ ([\w\.]+) # key
19
+ (?:\s*=\s*?|:\s+?) # separator
20
+ ( # optional value begin
21
+ '(?:\\'|[^'])*' # single quoted value
22
+ | # or
23
+ "(?:\\"|[^"])*" # double quoted value
24
+ | # or
25
+ [^\#\r\n]+ # unquoted value
26
+ )? # value end
27
+ \s* # trailing whitespace
28
+ (?:\#.*)? # optional comment
29
+ (?:$|\z) # end of line
30
30
  /x
31
31
 
32
32
  class << self
@@ -44,7 +44,14 @@ module Dotenv
44
44
  end
45
45
 
46
46
  def call
47
- @string.split(/[\n\r]+/).each do |line|
47
+ # Convert line breaks to same format
48
+ lines = @string.gsub(/\r\n?/, "\n")
49
+ # Process matches
50
+ lines.scan(LINE).each do |key, value|
51
+ @hash[key] = parse_value(value || "")
52
+ end
53
+ # Process non-matches
54
+ lines.gsub(LINE, "").split(/[\n\r]+/).each do |line|
48
55
  parse_line(line)
49
56
  end
50
57
  @hash
@@ -53,10 +60,7 @@ module Dotenv
53
60
  private
54
61
 
55
62
  def parse_line(line)
56
- if (match = line.match(LINE))
57
- key, value = match.captures
58
- @hash[key] = parse_value(value || "")
59
- elsif line.split.first == "export"
63
+ if line.split.first == "export"
60
64
  if variable_not_set?(line)
61
65
  raise FormatError, "Line #{line.inspect} has an unset variable"
62
66
  end
@@ -65,7 +69,7 @@ module Dotenv
65
69
 
66
70
  def parse_value(value)
67
71
  # Remove surrounding quotes
68
- value = value.strip.sub(/\A(['"])(.*)\1\z/, '\2')
72
+ value = value.strip.sub(/\A(['"])(.*)\1\z/m, '\2')
69
73
 
70
74
  if Regexp.last_match(1) == '"'
71
75
  value = unescape_characters(expand_newlines(value))
@@ -1,3 +1,3 @@
1
1
  module Dotenv
2
- VERSION = "2.4.0".freeze
2
+ VERSION = "2.5.0".freeze
3
3
  end
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: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brandon Keepers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-24 00:00:00.000000000 Z
11
+ date: 2018-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -92,7 +92,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
92
  version: '0'
93
93
  requirements: []
94
94
  rubyforge_project:
95
- rubygems_version: 2.6.11
95
+ rubygems_version: 2.6.13
96
96
  signing_key:
97
97
  specification_version: 4
98
98
  summary: Loads environment variables from `.env`.