Skip to content

Commit

Permalink
Merge pull request pyupio#316 from pyupio/nicholas/support-advisory-m…
Browse files Browse the repository at this point in the history
…ultiline

Support line breaks on Advisories
  • Loading branch information
rafaelpivato authored Jan 11, 2021
2 parents e09d12f + ad34959 commit 3f75507
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ History

* Provide CVSS scores on full report, when available
* Fixed used DB wrong info
* Support line breaks on advisories

1.10.1 (2021-01-03)
-------------------
Expand Down
22 changes: 14 additions & 8 deletions safety/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,16 +135,22 @@ def render(vulns, full, checked_packages, used_db):
))
table.append(SheetReport.REPORT_SECTION)

descr = get_advisory(vuln)

for pn, paragraph in enumerate(descr.replace('\r', '').split('\n\n')):
if pn:
table.append("| {:76} |".format(''))
for line in textwrap.wrap(paragraph, width=76):
advisory_lines = get_advisory(vuln).replace(
'\r', ''
).splitlines()

for line in advisory_lines:
if line == '':
table.append("| {:76} |".format(" "))
for wrapped_line in textwrap.wrap(line, width=76):
try:
table.append("| {:76} |".format(line.encode('utf-8')))
table.append("| {:76} |".format(
wrapped_line.encode('utf-8')
))
except TypeError:
table.append("| {:76} |".format(line))
table.append("| {:76} |".format(
wrapped_line
))
# append the REPORT_SECTION only if this isn't the last entry
if n + 1 < len(vulns):
table.append(SheetReport.REPORT_SECTION)
Expand Down

0 comments on commit 3f75507

Please sign in to comment.