Skip to content

Commit cb3131a

Browse files
authored
Merge pull request #240 from mitre/encoding_fix
Set encoding of given Inspec JSON based on file bom if present.
2 parents 6b838ad + aef4d5c commit cb3131a

File tree

5 files changed

+8
-7
lines changed

5 files changed

+8
-7
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
platform: [ ubuntu-16.04, ubuntu-latest, macos-latest, windows-latest ]
16-
ruby: [ 2.5, 2.6, 2.7 ]
16+
ruby: [ 2.7 ]
1717
runs-on: ${{ matrix.platform }}
1818

1919
steps:

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ inherit_from: .rubocop_todo.yml
44
require: rubocop-minitest
55

66
AllCops:
7-
TargetRubyVersion: 2.5
7+
TargetRubyVersion: 2.7
88
Exclude:
99
- Gemfile
1010
- Rakefile

inspec_tools.gemspec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
1818
'0.0.0.1.ENOGVB'
1919
end
2020
spec.authors = ['Robert Thew', 'Matthew Dromazos', 'Rony Xavier', 'Aaron Lippold']
21-
spec.email = ['rthew@mitre.org']
21+
spec.email = ['saf@mitre.org']
2222
spec.summary = 'Converter utils for Inspec'
2323
spec.description = 'Converter utils for Inspec that can be included as a gem or used from the command line'
2424
spec.homepage = 'https://inspec-tools.mitre.org/'
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
2828
spec.executables << 'inspec_tools'
2929
spec.require_paths = ['lib']
3030

31-
spec.required_ruby_version = '>= 2.5'
31+
spec.required_ruby_version = '>= 2.7'
3232

3333
spec.add_runtime_dependency 'colorize', '~> 0'
3434
spec.add_runtime_dependency 'git-lite-version-bump', '>= 0.17.3'

lib/inspec_tools/inspec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
module InspecTools
1616
class Inspec
1717
def initialize(inspec_json, metadata = {})
18-
@json = JSON.parse(inspec_json.gsub(/\\+u0000/, ''))
18+
@json = JSON.parse(inspec_json)
1919
@metadata = metadata
2020
end
2121

lib/inspec_tools/plugin_cli.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ def xccdf2inspec
6262
option :metadata, required: false, type: :string, aliases: '-m',
6363
desc: 'path to JSON file with additional host metadata for the XCCDF file'
6464
def inspec2xccdf
65-
json = File.read(options[:inspec_json])
65+
io = File.open(options[:inspec_json], 'rb')
66+
io.set_encoding_by_bom
6667
metadata = options[:metadata] ? JSON.parse(File.read(options[:metadata])) : {}
67-
inspec_tool = InspecTools::Inspec.new(json, metadata)
68+
inspec_tool = InspecTools::Inspec.new(io.read, metadata)
6869
attr_hsh = YAML.load_file(options[:attributes])
6970
xccdf = inspec_tool.to_xccdf(attr_hsh)
7071
File.write(options[:output], xccdf)

0 commit comments

Comments
 (0)