enforce utf encoding for cli output (#3376)

* enforce utf encoding for cli output
* add profile with wrong character set

Signed-off-by: Christoph Hartmann <chris@lollyrock.com>
This commit is contained in:
Christoph Hartmann 2018-09-10 20:37:43 +02:00 committed by Jared Quick
parent 2afe1bc937
commit 0e0b808e9b
5 changed files with 26 additions and 1 deletions

View file

@ -149,7 +149,7 @@ module Inspec::Reporters
message_to_format = ''
message_to_format += "#{INDICATORS[indicator]} " unless indicator.nil?
message_to_format += message.to_s.lstrip
message_to_format += message.to_s.lstrip.force_encoding(Encoding::UTF_8)
format_with_color(color, indent_lines(message_to_format, indentation))
end

View file

@ -442,4 +442,13 @@ Test Summary: \e[38;5;41m2 successful\e[0m, 0 failures, 0 skipped\n"
out.exit_status.must_equal 0
end
end
describe 'when using a profile with non-UTF characters and wrong encoding' do
let(:out) { inspec('exec ' + File.join(profile_path, 'wrong-char-profile') + ' --no-create-lockfile') }
it 'completes the run with failed controls but no exception' do
out.stderr.must_be_empty
out.exit_status.must_equal 0
end
end
end

View file

@ -0,0 +1,7 @@
control 'char' do
title "ensure we have the right characterset"
desc "Ensure we do not freak out with “"
describe inspec.profile.file('ascii').force_encoding(Encoding::ISO_8859_1) do
it { should_not match(/conceptually/) }
end
end

View file

@ -0,0 +1 @@
मन

View file

@ -0,0 +1,8 @@
name: wrong-char-profile
title: tests the cli output with non-utf chars
maintainer: The Authors
copyright: The Authors
copyright_email: you@example.com
license: All Rights Reserved
summary: An InSpec Compliance Profile
version: 0.1.0