Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #14932 - set default strings parser encoding to UTF-8 #21

Merged
merged 1 commit into from May 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/kafo_parsers/puppet_module_parser.rb
Expand Up @@ -45,7 +45,7 @@ def initialize(file)
else
Puppet.parse_config
end
Encoding.default_external = Encoding::UTF_8 if defined?(Encoding) && Encoding.respond_to?(:default_external=)
Encoding.default_external = Encoding::UTF_8 if defined?(Encoding)
@@puppet_initialized = true
end

Expand Down
1 change: 1 addition & 0 deletions lib/kafo_parsers/puppet_strings_module_parser.rb
Expand Up @@ -42,6 +42,7 @@ def initialize(file)
raise KafoParsers::ParseError, "'#{command}' returned error\n#{@raw_json}"
end

Encoding.default_external = Encoding::UTF_8 if defined?(Encoding)
begin
@complete_hash = ::JSON.parse(@raw_json)
rescue ::JSON::ParserError => e
Expand Down
8 changes: 8 additions & 0 deletions test/kafo_parsers/puppet_strings_parser_test.rb
@@ -1,3 +1,4 @@
# encoding: utf-8
require 'test_helper'
require 'kafo_parsers/puppet_strings_module_parser'

Expand Down Expand Up @@ -91,6 +92,13 @@ module KafoParsers
specify { conditions['password'].must_equal '$db_type == \'mysql\' && $username != \'root\'' }
end
end

describe 'with UTF-8 manifest' do
let(:manifest) { "# e✗amp✓e\n" + BASIC_MANIFEST.sub('class testing(', 'class testingutf8(') }
let(:data) { PuppetStringsModuleParser.parse(ManifestFileFactory.build(manifest).path) }
let(:parameters) { data[:parameters] }
specify { parameters.must_include 'version' }
end
end
end
end