forked from acidprime/puppet-catalog-diff
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
Fix "Error: invalid byte sequence in UTF-8" error when retrieving catalogues with invalid encoding from PuppetDB on Puppet 3 server #38
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
90ab96e
Fix problem where a nodes details wouldn't load/show in puppet-catalo…
JohnEricson de0fefd
Merge remote-tracking branch 'upstream/master'
JohnEricson 95ace28
Added link to upload_facts.rb script and documentation for when it's …
JohnEricson fe74306
Clarified documentation about which Puppet versions the upload_facts.…
JohnEricson d0af71a
Merge remote-tracking branch 'remotes/upstream/master'
JohnEricson 0905eaa
Fix problem "Error: invalid byte sequence in UTF-8" that happens when…
JohnEricson fad6448
Adds backward compatibility to retrieve catalogs from older PuppetDB …
JohnEricson f14f17a
Revert "Adds backward compatibility to retrieve catalogs from older P…
JohnEricson 8ef2694
Add unit test of function compare_resources to recreate error when sh…
JohnEricson f2390a2
Cleaned up output text from development to make the code cleaner.
JohnEricson 355beaf
Removed Ruby warning "WARNING: Using `expect { }.not_to raise_error(S…
JohnEricson e7cabb5
Refactored validate encoding code for string diff to function validat…
JohnEricson File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm used to dealing with this by forcing locales in the environment. Does this have any side effects, such as deteriorating characters in a
C
environment for ex?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a unit test to this PR that reproduces the problem. This test adds latin1 data to the content of a file and test to show the diff. Without this fix the test will fail with mentioned error on line 91.
Even if I try to run the test like
LC_ALL=C pdk test unit --verbose
it gives me an error without the fix so I don't think it can be solved only by setting environment variables. I set default encoding to UTF-8 in the test on line 86 and 87 to make the test run consistently independent ofLC_ALL
, so to test with other environment variables you might want to remove these lines, but it still failed for me without these while running withLC_ALL=C
.The fix passes all tests so I think it shouldn't deteriorate characters that has worked fine in earlier versions. The fix only replaces invalid characters with � in diffs where the program else would have crashed. So it makes the program more robust to handle other encodings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
It could be interesting to have a wrapper function for that so we can just call:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I refactored the code into that function now. Much better! Unit test still runs fine and I also tested diffing different branches on a Puppet 5 master as well as diffing between a Puppet 3 and 5 Master and it works fine. So this should be solved now! 🙂