From ba42fffed00480b2f5fc82f5c36fefaf23f0f6a0 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 10 Feb 2012 18:07:59 -0800 Subject: [PATCH] Convert line endings to Unix-style [GH-727] --- CHANGELOG.md | 1 + lib/vagrant/guest/redhat.rb | 5 +++++ lib/vagrant/util/line_ending_helpers.rb | 14 ++++++++++++++ .../vagrant/util/line_endings_helper_test.rb | 16 ++++++++++++++++ 4 files changed, 36 insertions(+) create mode 100644 lib/vagrant/util/line_ending_helpers.rb create mode 100644 test/unit/vagrant/util/line_endings_helper_test.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 392560de8..d4dac3be0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ - Fix issue where starting a VM on some systems was incorrectly treated as failing. [GH-720] - It is now an error to specify the packaging `output` as a directory. [GH-730] + - Unix-style line endings are used properly for guest OS. [GH-727] ## 0.9.7 (February 9, 2012) diff --git a/lib/vagrant/guest/redhat.rb b/lib/vagrant/guest/redhat.rb index c098a4ba4..377cd88ab 100644 --- a/lib/vagrant/guest/redhat.rb +++ b/lib/vagrant/guest/redhat.rb @@ -1,6 +1,7 @@ require 'set' require 'tempfile' +require 'vagrant/util/line_ending_helpers' require 'vagrant/util/template_renderer' module Vagrant @@ -8,6 +9,7 @@ module Vagrant class Redhat < Linux # Make the TemplateRenderer top-level include Vagrant::Util + include Vagrant::Util::LineEndingHelpers def configure_networks(networks) # Accumulate the configurations to add to the interfaces file as @@ -28,6 +30,9 @@ module Vagrant entry = TemplateRenderer.render("guests/redhat/network_#{network[:type]}", :options => network) + # Convert line endings to unix-style + entry = dos_to_unix(entry) + temp = Tempfile.new("vagrant") temp.write(entry) temp.close diff --git a/lib/vagrant/util/line_ending_helpers.rb b/lib/vagrant/util/line_ending_helpers.rb new file mode 100644 index 000000000..9a88b8db2 --- /dev/null +++ b/lib/vagrant/util/line_ending_helpers.rb @@ -0,0 +1,14 @@ +module Vagrant + module Util + module LineEndingHelpers + # Converts line endings to unix-style line endings in the + # given string. + # + # @param [String] string Original string + # @return [String] The fixed string + def dos_to_unix(string) + string.gsub("\r\n", "\n") + end + end + end +end diff --git a/test/unit/vagrant/util/line_endings_helper_test.rb b/test/unit/vagrant/util/line_endings_helper_test.rb new file mode 100644 index 000000000..29454a323 --- /dev/null +++ b/test/unit/vagrant/util/line_endings_helper_test.rb @@ -0,0 +1,16 @@ +require File.expand_path("../../../base", __FILE__) + +require "vagrant/util/line_ending_helpers" + +describe Vagrant::Util::LineEndingHelpers do + let(:klass) do + Class.new do + extend Vagrant::Util::LineEndingHelpers + end + end + + it "should convert DOS to unix-style line endings" do + klass.dos_to_unix("foo\r\nbar\r\n").should == "foo\nbar\n" + end +end +