Skip to content

Commit 0dbfd34

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 bbce565 commit 0dbfd34

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
@@ -79,11 +79,10 @@ def create_etag(data_src, url, etag_key):
7979
return True
8080

8181

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

107-
for index, line in enumerate(lines):
108-
line = line.strip()
109-
if index == 0 and line.startswith("---"):
106+
for index, line in enumerate(lines.split("\n")):
107+
if index == 0 and line.strip().startswith("---"):
110108
splitter = fmlines
111-
elif line.startswith("---"):
109+
elif line.strip().startswith("---"):
112110
splitter = mdlines
113111
else:
114112
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)