Skip to content

Commit

Permalink
Merge pull request #2513 from AriaXLi/fact-3135
Browse files Browse the repository at this point in the history
(FACT-3135) Add support for yaml anchors in Facter 4
  • Loading branch information
mhashizume authored Aug 16, 2022
2 parents 832c9b5 + bbc2d3b commit 2844695
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/facter/custom_facts/util/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ def parse_results
cont = content.gsub(TIME, '"\1"')

if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0') # Ruby 2.6+
YAML.safe_load(cont, permitted_classes: [Date])
YAML.safe_load(cont, permitted_classes: [Date], aliases: true)
else
YAML.safe_load(cont, [Date])
YAML.safe_load(cont, [Date], [], [], true)
end
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/custom_facts/util/parser_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,16 @@ def expects_to_parse_powershell(cmd, result)
let(:yaml_parser) { LegacyFacter::Util::Parser::YamlParser.new(nil, yaml_content) }

describe '#parse_results' do
context 'when yaml anchors are present' do
let(:yaml_content) { load_fixture('external_fact_yaml_anchor').read }

it 'parses the yaml anchors' do
expected_result = { 'one' => { 'test' => { 'a' => ['foo'] } }, 'two' => { 'TEST' => { 'A' => ['foo'] } } }

expect(yaml_parser.parse_results).to eq(expected_result)
end
end

context 'when yaml contains Time formatted fields' do
context 'when time zone is present' do
let(:yaml_content) { load_fixture('external_fact_yaml').read }
Expand Down
8 changes: 8 additions & 0 deletions spec/fixtures/external_fact_yaml_anchor
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
one:
test:
a: &a1
- foo
two:
TEST:
A: *a1

0 comments on commit 2844695

Please sign in to comment.