mirror of
https://github.com/inspec/inspec
synced 2024-11-23 05:03:07 +00:00
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:
parent
2afe1bc937
commit
0e0b808e9b
5 changed files with 26 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
1
test/unit/mock/profiles/wrong-char-profile/files/ascii
Normal file
1
test/unit/mock/profiles/wrong-char-profile/files/ascii
Normal file
|
@ -0,0 +1 @@
|
|||
मन
|
8
test/unit/mock/profiles/wrong-char-profile/inspec.yml
Normal file
8
test/unit/mock/profiles/wrong-char-profile/inspec.yml
Normal 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
|
Loading…
Reference in a new issue