problem_report: validate key names in ProblemReport.load - #646
Open
bdrung wants to merge 2 commits into
Open
Conversation
The documentation for `ProblemReport.load()` says: > If binary is False, binary data is not loaded; the dictionary key is > created, but its value will be an empty string. Commit 64820a0 ("apport-unpack: Fix ValueError: ['separator'] has no binary content") changed this behavior to fix a crash in apport-unpack. Setting non-loaded values to `None` will make type hints more complicated and less useful. Values in the problem report should not be allowed to be `None`. Instead of adding dictionary keys with a special value for not loaded keys, just let `load()` return the keys that were skipped. This reduces guess work and make the code more robust. Remove `ProblemReport.has_removed_fields()` since that information is lost and this function was only used in Apport tests.
Apport report files consist of key/value pairs based on the standard RFC822 format, except that Apport uses case sensitive keys. Key names must only contain numbers, letters, '.', '_', and '-'. This is validated in `ProblemReport.__setitem__`, but not when loading a report in `ProblemReport.load`. So use `ProblemReport.__setitem__` in `ProblemReport.load` as well. Bug: https://launchpad.net/bugs/2161697
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #646 +/- ##
==========================================
- Coverage 84.48% 84.48% -0.01%
==========================================
Files 106 106
Lines 21044 21036 -8
Branches 3192 3190 -2
==========================================
- Hits 17780 17772 -8
Misses 2790 2790
Partials 474 474 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Apport report files consist of key/value pairs based on the standard RFC822 format, except that Apport uses case sensitive keys. Key names must only contain numbers, letters, '.', '_', and '-'. This is validated in
ProblemReport.__setitem__, but not when loading a report inProblemReport.load.So use
ProblemReport.__setitem__inProblemReport.loadas well.This PR depends on #580 landing first.
Bug: https://launchpad.net/bugs/2161697