Skip to content

Commit

Permalink
split_markdown_front_matter: Do not strip lines
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Hritik14 committed Mar 29, 2021
1 parent bbce565 commit 0dbfd34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions vulnerabilities/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@ def create_etag(data_src, url, etag_key):
return True


def split_markdown_front_matter(lines: Iterable) -> Tuple[str, str]:
def split_markdown_front_matter(lines: str) -> Tuple[str, str]:
"""
This function splits lines into markdown front matter and the markdown body
and returns list of lines for both
NOTE: lines is expected to be an iterable containing strings
for example :
lines =
Expand All @@ -94,7 +93,7 @@ def split_markdown_front_matter(lines: Iterable) -> Tuple[str, str]:
---
# Markdown starts here
get_markdown_front_matter(lines) would return
split_markdown_front_matter(lines) would return
['title: ISTIO-SECURITY-2019-001','description: Incorrect access control.'
,'cves: [CVE-2019-12243]'],
["# Markdown starts here"]
Expand All @@ -104,11 +103,10 @@ def split_markdown_front_matter(lines: Iterable) -> Tuple[str, str]:
mdlines = []
splitter = mdlines

for index, line in enumerate(lines):
line = line.strip()
if index == 0 and line.startswith("---"):
for index, line in enumerate(lines.split("\n")):
if index == 0 and line.strip().startswith("---"):
splitter = fmlines
elif line.startswith("---"):
elif line.strip().startswith("---"):
splitter = mdlines
else:
splitter.append(line)
Expand Down
2 changes: 1 addition & 1 deletion vulnerabilities/importers/mozilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def get_advisories_from_yml(self, mfsa_id, lines) -> List[Advisory]:
return advisories

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

Expand Down

0 comments on commit 0dbfd34

Please sign in to comment.