Skip to content

Commit 2fb4838

Browse files
committed
Use a more obvious version and reorder imports
Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
1 parent 92ea738 commit 2fb4838

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

vulnerabilities/helpers.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def __lt__(self, other):
167167
return affected_package_with_patched_package_objects
168168

169169

170-
def split_markdown_front_matter(text: str) -> Tuple[str, str]:
170+
def split_markdown_front_matter(lines: str) -> Tuple[str, str]:
171171
r"""
172172
Split text into markdown front matter and the markdown body
173173
Return ("", text) for text with non existing front matter
@@ -180,15 +180,19 @@ def split_markdown_front_matter(text: str) -> Tuple[str, str]:
180180
... # Markdown starts here
181181
... '''
182182
>>> split_markdown_front_matter(text)
183-
('title: DUMMY-SECURITY-2019-001\ndescription: Incorrect access control.\ncves: [CVE-2042-1337]\n', '\n# Markdown starts here\n')
183+
('title: DUMMY-SECURITY-2019-001\ndescription: Incorrect access control.\ncves: [CVE-2042-1337]', '# Markdown starts here\n')
184184
"""
185-
186-
front_matter = ""
187-
body = text
188-
text = text.replace("\r\n", "\n")
189-
linezero, _, text = text.partition("---\n")
190-
191-
if not linezero: # nothing before first ---
192-
front_matter, _, body = text.partition("---")
193-
194-
return front_matter, body
185+
fmlines = []
186+
mdlines = []
187+
splitter = mdlines
188+
189+
lines = lines.replace("\r\n", "\n")
190+
for index, line in enumerate(lines.split("\n")):
191+
if index == 0 and line.strip().startswith("---"):
192+
splitter = fmlines
193+
elif line.strip().startswith("---"):
194+
splitter = mdlines
195+
else:
196+
splitter.append(line)
197+
198+
return "\n".join(fmlines), "\n".join(mdlines)

vulnerabilities/importers/istio.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131

3232
from vulnerabilities.data_source import Advisory
3333
from vulnerabilities.data_source import GitDataSource
34+
from vulnerabilities.data_source import Reference
35+
from vulnerabilities.helpers import nearest_patched_package
3436
from vulnerabilities.helpers import split_markdown_front_matter
3537
from vulnerabilities.package_managers import GitHubTagsAPI
36-
from vulnerabilities.helpers import nearest_patched_package
3738

3839
is_release = re.compile(r"^[\d.]+$", re.IGNORECASE).match
3940

0 commit comments

Comments
 (0)