diff options
author | Samuel Giddins <segiddins@segiddins.me> | 2016-08-08 15:01:11 -0500 |
---|---|---|
committer | Samuel Giddins <segiddins@segiddins.me> | 2016-08-08 15:01:11 -0500 |
commit | f5b61c41ca3bef865099056a45b6494b0cc1b0cf (patch) | |
tree | ff481ef9190c1f2f320ccc1f0b3ee574635eba18 | |
parent | e23ea1519cfd9164053cb0eca84c3447ed6a2d57 (diff) | |
download | bundler-f5b61c41ca3bef865099056a45b6494b0cc1b0cf.tar.gz |
[YAMLSerializer] Allow loading with CRLF line endingsseg-settings-crlf
-rw-r--r-- | lib/bundler/yaml_serializer.rb | 2 | ||||
-rw-r--r-- | spec/bundler/yaml_serializer_spec.rb | 23 |
2 files changed, 24 insertions, 1 deletions
diff --git a/lib/bundler/yaml_serializer.rb b/lib/bundler/yaml_serializer.rb index dede8fd5fd..3c9eccafc2 100644 --- a/lib/bundler/yaml_serializer.rb +++ b/lib/bundler/yaml_serializer.rb @@ -52,7 +52,7 @@ module Bundler stack = [res] last_hash = nil last_empty_key = nil - str.split("\n").each do |line| + str.split(/\r?\n/).each do |line| if match = HASH_REGEX.match(line) indent, key, _, val = match.captures key = convert_to_backward_compatible_key(key) diff --git a/spec/bundler/yaml_serializer_spec.rb b/spec/bundler/yaml_serializer_spec.rb index 0b3261336c..bf86d2a076 100644 --- a/spec/bundler/yaml_serializer_spec.rb +++ b/spec/bundler/yaml_serializer_spec.rb @@ -125,6 +125,29 @@ describe Bundler::YAMLSerializer do expect(serializer.load(yaml)).to eq(hash) end + + it "handles windows-style CRLF line endings" do + yaml = strip_whitespace(<<-YAML).gsub("\n", "\r\n") + --- + nested_hash: + contains_array: + - "Why shouldn't you write with a broken pencil?" + - "Because it's pointless!" + - oh so silly + YAML + + hash = { + "nested_hash" => { + "contains_array" => [ + "Why shouldn't you write with a broken pencil?", + "Because it's pointless!", + "oh so silly", + ], + }, + } + + expect(serializer.load(yaml)).to eq(hash) + end end describe "against yaml lib" do |