Skip to content
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

Bug Fix: Fix Inline Dictionary For YAML Files #501

Merged
merged 7 commits into from
Jan 11, 2022

Conversation

jpdakran
Copy link
Member

@jpdakran jpdakran commented Jan 7, 2022

Problem

  • When running detect-secrets on YAML files - there is a miscalculation that occurs when calculating the line number of an inline dictionary (FlowMapping).
  • This is an issue with the PyYAML library.
  • This issue occurs when there is an empty line after the inline dictionary.
  • An example of where the miscalculation occurs:
dictionary: 
     - {keyA: valueA, keyB: valueB, keyC: valueC}
     

Solution

  • This solution was inspired by this PR but was expanded on to fix a few other use-cases
  • The parser keeps track of the the start of the FlowMapping character under self.marks
  • We need to use this values line number when the inline dictionary has a key on the same line as the start of the FlowMapping.
  • The PR above handles the case only when there is a SINGLE key value pair followed by an empty line. Ex. {key: value}
  • To handle the cases where there are multiple key value pairs on a single line - we must check that the next upcoming tokens are of type FlowEntryToken, KeyToken (Comma, new Key). This will tell us if this dictionary has more values on the same line. Ex. {keyA: valueA, keyB: valueB, keyC: valueC}

Verification

  • A suite of unit tests were created to validate the approach.

@jpdakran jpdakran merged commit c21ed92 into master Jan 11, 2022
@KevinHock
Copy link
Collaborator

Great stuff @jpdakran!

@jpdakran jpdakran deleted the bug-fix/inline-dictionary-yaml-support branch February 11, 2022 21:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

yaml tranformer fails on a certain case where the file ends with a blank line
3 participants