Skip to content

Commit d7ced8b

Browse files
committed
split_markdown_front_matter: Do not strip lines
spaces are important, otherwise it would fail to produce a valid yaml front matter in case of https://raw.githubusercontent.com/mozilla/foundation-security-advisories/master/announce/2012/mfsa2012-85.md Anyway, line shouldn't be altered in a splitter. Signed-off-by: Hritik Vijay <hritikxx8@gmail.com>
1 parent df9786d commit d7ced8b

2 files changed

Lines changed: 6 additions & 8 deletions

File tree

vulnerabilities/helpers.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,10 @@ def create_etag(data_src, url, etag_key):
8080
return True
8181

8282

83-
def split_markdown_front_matter(lines: Iterable) -> Tuple[str, str]:
83+
def split_markdown_front_matter(lines: str) -> Tuple[str, str]:
8484
"""
8585
This function splits lines into markdown front matter and the markdown body
8686
and returns list of lines for both
87-
NOTE: lines is expected to be an iterable containing strings
8887
8988
for example :
9089
lines =
@@ -95,7 +94,7 @@ def split_markdown_front_matter(lines: Iterable) -> Tuple[str, str]:
9594
---
9695
# Markdown starts here
9796
98-
get_markdown_front_matter(lines) would return
97+
split_markdown_front_matter(lines) would return
9998
['title: ISTIO-SECURITY-2019-001','description: Incorrect access control.'
10099
,'cves: [CVE-2019-12243]'],
101100
["# Markdown starts here"]
@@ -105,11 +104,10 @@ def split_markdown_front_matter(lines: Iterable) -> Tuple[str, str]:
105104
mdlines = []
106105
splitter = mdlines
107106

108-
for index, line in enumerate(lines):
109-
line = line.strip()
110-
if index == 0 and line.startswith("---"):
107+
for index, line in enumerate(lines.split("\n")):
108+
if index == 0 and line.strip().startswith("---"):
111109
splitter = fmlines
112-
elif line.startswith("---"):
110+
elif line.strip().startswith("---"):
113111
splitter = mdlines
114112
else:
115113
splitter.append(line)

vulnerabilities/importers/mozilla.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def get_advisories_from_yml(self, mfsa_id, lines) -> List[Advisory]:
8181
return advisories
8282

8383
def get_advisories_from_md(self, mfsa_id, lines) -> List[Advisory]:
84-
yamltext, mdtext = split_markdown_front_matter(lines)
84+
yamltext, mdtext = split_markdown_front_matter(lines.read())
8585
data = yaml.safe_load(yamltext)
8686
data["mfsa_id"] = mfsa_id
8787

0 commit comments

Comments
 (0)