Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion cbom/parser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,18 @@ def get_detection_contexts(locations):

def parse_location(physical_location):
file_path = physical_location['artifactLocation']['uri']

# use line numbers from region if possible as they give exist location
if region := physical_location.get('region'):
start_line = region['startLine']
end_line = region.get('endLine', start_line) # Use start_line if endLine doesn't exist
line_numbers = list(range(start_line, end_line + 1))
else:
line_numbers = []

if context_region := physical_location.get('contextRegion'):
line_numbers = list(range(context_region['startLine'], context_region['endLine'] + 1))
if not line_numbers:
line_numbers = list(range(context_region['startLine'], context_region['endLine'] + 1))
code_snippet = context_region.get('snippet').get('text')
return DetectionContext(file_path=file_path, line_numbers=line_numbers, additional_context=code_snippet)

Expand Down