File tree Expand file tree Collapse file tree
lib/facter/custom_facts/util Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,10 +13,6 @@ require:
1313Layout/LineLength :
1414 Max : 120
1515
16- Lint/RescueException :
17- Exclude :
18- - ' lib/facter/custom_facts/util/parser.rb'
19-
2016Lint/RaiseException :
2117 Enabled : true
2218
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ def content
5656 # wrapper.
5757 def results
5858 parse_results
59- rescue Exception => e
59+ rescue StandardError => e
6060 Facter . log_exception ( e , "Failed to handle #{ filename } as #{ self . class } facts: #{ e . message } " )
6161 nil
6262 end
@@ -68,8 +68,8 @@ def parse_results
6868 def parse_executable_output ( output )
6969 res = nil
7070 begin
71- res = YAML . safe_load output
72- rescue Exception => e
71+ res = YAML . safe_load ( output , [ Symbol , Time ] )
72+ rescue StandardError => e
7373 Facter . debug ( "Could not parse executable fact output as YAML or JSON (#{ e . message } )" )
7474 end
7575 res = KeyValuePairOutputFormat . parse output unless res . is_a? ( Hash )
Original file line number Diff line number Diff line change @@ -162,6 +162,21 @@ def expects_parser_to_return_nil_for_directory(path)
162162 expects_script_to_return ( cmd , yaml_data , data )
163163 end
164164
165+ it 'handles Symbol correctly' do
166+ yaml_data = "---\n :one: :two\n three: four\n "
167+ exptected_data = { :one => :two , 'three' => 'four' }
168+ expects_script_to_return ( cmd , yaml_data , exptected_data )
169+ end
170+
171+ it 'handles Time correctly' do
172+ yaml_data = "---\n first: 2020-07-15 05:38:12.427678398 +00:00\n "
173+ allow ( Facter ::Core ::Execution ) . to receive ( :exec ) . with ( cmd ) . and_return ( yaml_data )
174+ allow ( File ) . to receive ( :executable? ) . with ( cmd ) . and_return ( true )
175+ allow ( FileTest ) . to receive ( :file? ) . with ( cmd ) . and_return ( true )
176+
177+ expect ( LegacyFacter ::Util ::Parser . parser_for ( cmd ) . results [ 'first' ] ) . to be_a ( Time )
178+ end
179+
165180 it 'returns an empty hash when the script returns nil' do
166181 expects_script_to_return ( cmd , nil , { } )
167182 end
You can’t perform that action at this time.
0 commit comments