From 0dbfd34f96447758636a2c7d17613bb145a69089 Mon Sep 17 00:00:00 2001 From: Hritik Vijay Date: Fri, 26 Mar 2021 05:08:41 +0530 Subject: [PATCH] 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 --- vulnerabilities/helpers.py | 12 +++++------- vulnerabilities/importers/mozilla.py | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/vulnerabilities/helpers.py b/vulnerabilities/helpers.py index de4c1718a..dceaeb961 100644 --- a/vulnerabilities/helpers.py +++ b/vulnerabilities/helpers.py @@ -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 = @@ -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"] @@ -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) diff --git a/vulnerabilities/importers/mozilla.py b/vulnerabilities/importers/mozilla.py index f1a988cef..4d45f9e78 100644 --- a/vulnerabilities/importers/mozilla.py +++ b/vulnerabilities/importers/mozilla.py @@ -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