Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Yelp/detect-secrets into …
Browse files Browse the repository at this point in the history
…dakranj-add-rational-for-heuristic-constraint
  • Loading branch information
jpdakran committed Feb 7, 2022
2 parents 27f230a + 426ae5b commit 222619e
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
3 changes: 3 additions & 0 deletions detect_secrets/transformers/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ def _compose_node_shim(
node.__line__ = line + 1

if node.tag.endswith(':map'):
# Reset the inline flow mapping key when the end of a mapping is reached
# to avoid complications with empty mappings
self.is_inline_flow_mapping_key = False
return _tag_dict_values(node)

# TODO: Not sure if need to do :seq
Expand Down
71 changes: 71 additions & 0 deletions tests/transformers/yaml_transformer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,3 +357,74 @@ def test_inline_dictionary_different_starting_line():
'__original_key__': 'b',
},
}

@staticmethod
def test_inline_empty_mapping_line_numbers():
file = mock_file_object(
textwrap.dedent("""
a: {}
b: "2"
""")[1:-1],
)

assert YAMLFileParser(file).json() == {
'a': {},
'b': {
'__value__': '2',
'__line__': 2,
'__original_key__': 'b',
},
}

@staticmethod
def test_inline_mapping_single_line_single_key_line_numbers():
file = mock_file_object(
textwrap.dedent("""
a: {b: "2"}
c: "3"
""")[1:-1],
)

assert YAMLFileParser(file).json() == {
'a': {
'b': {
'__value__': '2',
'__line__': 1,
'__original_key__': 'b',
},
},
'c': {
'__value__': '3',
'__line__': 2,
'__original_key__': 'c',
},
}

@staticmethod
def test_inline_mapping_single_line_multikey_line_numbers():
file = mock_file_object(
textwrap.dedent("""
a: {b: "2", c: "3"}
d: "4"
""")[1:-1],
)

assert YAMLFileParser(file).json() == {
'a': {
'b': {
'__value__': '2',
'__line__': 1,
'__original_key__': 'b',
},
'c': {
'__value__': '3',
'__line__': 1,
'__original_key__': 'c',
},
},
'd': {
'__value__': '4',
'__line__': 2,
'__original_key__': 'd',
},
}

0 comments on commit 222619e

Please sign in to comment.