Skip to content

Commit 813522c

Browse files
authored
Merge pull request #751 from rodjek/issue-748
Open manifest as binary when writing fixed manifest
2 parents 154613d + d394671 commit 813522c

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

lib/puppet-lint/bin.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def run
6565
end
6666

6767
next unless PuppetLint.configuration.fix && l.problems.none? { |r| r[:check] == :syntax }
68-
File.open(f, 'w') do |fd|
68+
File.open(f, 'wb') do |fd|
6969
fd.write(l.manifest)
7070
end
7171
end

spec/puppet-lint/bin_spec.rb

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require 'spec_helper'
22
require 'rspec/mocks'
33
require 'optparse'
4+
require 'tempfile'
45

56
class CommandRun
67
attr_accessor :stdout, :stderr, :exitstatus
@@ -442,4 +443,50 @@ def initialize(args)
442443

443444
its(:stdout) { is_expected.to match(%r{WARNING: lint:ignore:140chars comment on line 2 with no closing lint:endignore comment}) }
444445
end
446+
447+
context 'when fixing a file with \n line endings' do
448+
before(:context) do
449+
@windows_file = Tempfile.new('windows')
450+
@posix_file = Tempfile.new('posix')
451+
452+
@windows_file.binmode
453+
@posix_file.binmode
454+
455+
@windows_file.write("\r\n")
456+
@posix_file.write("\n")
457+
458+
@windows_file.close
459+
@posix_file.close
460+
end
461+
462+
after(:context) do
463+
@windows_file.unlink
464+
@posix_file.unlink
465+
end
466+
467+
let(:args) do
468+
[
469+
'--fix',
470+
@posix_file.path,
471+
@windows_file.path,
472+
]
473+
end
474+
475+
its(:exitstatus) { is_expected.to eq(0) }
476+
477+
it 'does not change the line endings' do
478+
File.open(@posix_file.path, 'rb') do |f|
479+
data = f.read
480+
481+
expect(data).to match(%r{\n\Z}m)
482+
expect(data).to_not match(%r{\r\n\Z}m)
483+
end
484+
485+
File.open(@windows_file.path, 'rb') do |f|
486+
data = f.read
487+
488+
expect(data).to match(%r{\r\n\Z}m)
489+
end
490+
end
491+
end
445492
end

0 commit comments

Comments
 (0)