summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Giddins <segiddins@segiddins.me>2017-07-20 11:42:32 -0500
committerSamuel Giddins <segiddins@segiddins.me>2017-07-20 11:42:32 -0500
commit6a635dea7c7a36ab8087d6b042915c83c9575c3f (patch)
tree81c07ce6ad8a146ceba2a06396c03637a79be2bc
parent50905839daa6c381b3759375d69194309c5f6544 (diff)
downloadbundler-seg-yaml-empty-string-values.tar.gz
[YAMLSerializer] Handle empty strings properlyseg-yaml-empty-string-values
-rw-r--r--lib/bundler/yaml_serializer.rb6
-rw-r--r--spec/bundler/yaml_serializer_spec.rb2
2 files changed, 5 insertions, 3 deletions
diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb
index 3c9eccafc2..0fd81c40ef 100644
--- a/lib/bundler/yaml_serializer.rb
+++ b/lib/bundler/yaml_serializer.rb
@@ -37,7 +37,7 @@ module Bundler
HASH_REGEX = /
^
([ ]*) # indentations
- (.*) # key
+ (.+) # key
(?::(?=(?:\s|$))) # : (without the lookahead the #key includes this when : is present in value)
[ ]?
(?: !\s)? # optional exclamation mark found with ruby 1.9.3
@@ -54,10 +54,10 @@ module Bundler
last_empty_key = nil
str.split(/\r?\n/).each do |line|
if match = HASH_REGEX.match(line)
- indent, key, _, val = match.captures
+ indent, key, quote, val = match.captures
key = convert_to_backward_compatible_key(key)
depth = indent.scan(/ /).length
- if val.empty?
+ if quote.empty? && val.empty?
new_hash = {}
stack[depth][key] = new_hash
stack[depth + 1] = new_hash
diff --git a/spec/bundler/yaml_serializer_spec.rb b/spec/bundler/yaml_serializer_spec.rb
index 361159e0da..d41befd14e 100644
--- a/spec/bundler/yaml_serializer_spec.rb
+++ b/spec/bundler/yaml_serializer_spec.rb
@@ -156,6 +156,7 @@ RSpec.describe Bundler::YAMLSerializer do
"a_joke" => {
"my-stand" => "I can totally keep secrets",
"but" => "The people I tell them to can't :P",
+ "wouldn't it be funny if this string were empty?" => "",
},
"more" => {
"first" => [
@@ -166,6 +167,7 @@ RSpec.describe Bundler::YAMLSerializer do
"What did the sea say to the sand?",
"Nothing, it simply waved.",
],
+ "array with empty string" => [""],
},
"sales" => {
"item" => "A Parachute",