Skip to content

Commit

Permalink
Merge pull request #240 from mitre/encoding_fix
Browse files Browse the repository at this point in the history
Set encoding of given Inspec JSON based on file bom if present.
  • Loading branch information
Bialogs authored Jul 28, 2021
2 parents 6b838ad + aef4d5c commit cb3131a
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
platform: [ ubuntu-16.04, ubuntu-latest, macos-latest, windows-latest ]
ruby: [ 2.5, 2.6, 2.7 ]
ruby: [ 2.7 ]
runs-on: ${{ matrix.platform }}

steps:
Expand Down
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ inherit_from: .rubocop_todo.yml
require: rubocop-minitest

AllCops:
TargetRubyVersion: 2.5
TargetRubyVersion: 2.7
Exclude:
- Gemfile
- Rakefile
Expand Down
4 changes: 2 additions & 2 deletions inspec_tools.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
'0.0.0.1.ENOGVB'
end
spec.authors = ['Robert Thew', 'Matthew Dromazos', 'Rony Xavier', 'Aaron Lippold']
spec.email = ['rthew@mitre.org']
spec.email = ['saf@mitre.org']
spec.summary = 'Converter utils for Inspec'
spec.description = 'Converter utils for Inspec that can be included as a gem or used from the command line'
spec.homepage = 'https://inspec-tools.mitre.org/'
Expand All @@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
spec.executables << 'inspec_tools'
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 2.5'
spec.required_ruby_version = '>= 2.7'

spec.add_runtime_dependency 'colorize', '~> 0'
spec.add_runtime_dependency 'git-lite-version-bump', '>= 0.17.3'
Expand Down
2 changes: 1 addition & 1 deletion lib/inspec_tools/inspec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
module InspecTools
class Inspec
def initialize(inspec_json, metadata = {})
@json = JSON.parse(inspec_json.gsub(/\\+u0000/, ''))
@json = JSON.parse(inspec_json)
@metadata = metadata
end

Expand Down
5 changes: 3 additions & 2 deletions lib/inspec_tools/plugin_cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ def xccdf2inspec
option :metadata, required: false, type: :string, aliases: '-m',
desc: 'path to JSON file with additional host metadata for the XCCDF file'
def inspec2xccdf
json = File.read(options[:inspec_json])
io = File.open(options[:inspec_json], 'rb')
io.set_encoding_by_bom
metadata = options[:metadata] ? JSON.parse(File.read(options[:metadata])) : {}
inspec_tool = InspecTools::Inspec.new(json, metadata)
inspec_tool = InspecTools::Inspec.new(io.read, metadata)
attr_hsh = YAML.load_file(options[:attributes])
xccdf = inspec_tool.to_xccdf(attr_hsh)
File.write(options[:output], xccdf)
Expand Down

0 comments on commit cb3131a

Please sign in to comment.