lib/framework/formatters/legacy_fact_formatter.rb in facter-4.0.25 vs lib/framework/formatters/legacy_fact_formatter.rb in facter-4.0.26
- old
+ new
@@ -58,11 +58,11 @@
def hash_to_facter_format(facts_hash)
@log.debug('Converting hash to pretty json')
pretty_json = JSON.pretty_generate(facts_hash)
@log.debug('Change key value delimiter from : to =>')
- pretty_json.gsub!(/^(.*?)(:)/, '\1 =>')
+ pretty_json.gsub!(/":/, '" =>')
@log.debug('Remove quotes from parent nodes')
pretty_json.gsub!(/\"(.*)\"\ =>/, '\1 =>')
@log.debug('Remove double backslashes from paths')
@@ -82,10 +82,12 @@
@log.debug('remove comas from query results')
pretty_fact_json.gsub(/^},/, '}')
end
def remove_comma_and_quation(output)
+ # quotation marks that come after \ are not removed
@log.debug('Remove unnecessary comma and quotation marks on root facts')
- output.split("\n").map! { |line| line =~ /^[\s]+/ ? line : line.gsub(/,$|\"/, '') }.join("\n")
+ output.split("\n")
+ .map! { |line| line =~ /^[\s]+/ ? line : line.gsub(/,$|(?<!\\)\"/, '').gsub('\\"', '"') }.join("\n")
end
end
end