Convert line endings to Unix-style [GH-727]

This commit is contained in:
Mitchell Hashimoto 2012-02-10 18:07:59 -08:00
parent 5c49d693d4
commit ba42fffed0
4 changed files with 36 additions and 0 deletions

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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