Skip to content
This repository has been archived by the owner on Jun 19, 2020. It is now read-only.

(FACT-2553) remove double backslashes from windows path #456

Merged
merged 2 commits into from
Apr 24, 2020

Conversation

oanatmaria
Copy link
Contributor

@oanatmaria oanatmaria commented Apr 16, 2020

Description of the problem: On Windows facts that contains paths (like path and system32 fact) are double backslashed when facter is executed without any formatter. When facter is executed with --yaml argument the same facts (path and system32) are single backslashed instead of double backslashed.

@oanatmaria oanatmaria added the bugfix Something isn't working label Apr 16, 2020
@oanatmaria oanatmaria requested review from a team April 16, 2020 09:38
@@ -65,7 +65,8 @@ def hash_to_facter_format(facts_hash)
@log.debug('Remove quotes from parent nodes')
pretty_json.gsub!(/\"(.*)\"\ =>/, '\1 =>')

pretty_json
@log.debug('Remove double backslashes from paths')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dangerous. UNC paths use double backslashes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After JSON.generate all backslashes are doubled, this means that UNC paths now have 4 backslashes. I simply want to revert that by replacing 2 backslashes with one, resulting, in this case, that UNC paths will be 2 backslashes.


expect(formatted_output).to eq(expected_output)
it 'formats path with double escaped backslashes' do
expect(yaml_formatter.format(resolved_fact_list)).to eq(expected_output)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect the resolved fact to contain a string with single backslashes (like 'C:\Program Files\...'), and have the formatter preserve that:

irb(main):003:0> puts YAML.dump('C:\Program')
--- C:\Program

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you described is exactly the behaviour of Facter 4. When facter-ng is executed with '--yaml' backslashes are not doubled, the need to double them came from the fact that facter 3 prints doubled backslashes when is executed with '--yaml'

@BogdanIrimie BogdanIrimie merged commit df99078 into master Apr 24, 2020
@BogdanIrimie BogdanIrimie deleted the FACT-2553 branch April 24, 2020 11:57
Filipovici-Andrei pushed a commit that referenced this pull request Apr 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bugfix Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants