From 5ea94d06e679f41faf86fb9344010c55bf426f46 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Sun, 29 Nov 2015 20:58:41 +0100 Subject: [PATCH 1/3] Catch YAML parse errors --- lib/Pico.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/Pico.php b/lib/Pico.php index 7f4b1c3..3ea121b 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -753,6 +753,8 @@ class Pico * @param string $rawContent the raw file contents * @param string[] $headers known meta headers * @return array parsed meta data + * @throws \Symfony\Component\Yaml\Exception\ParseException thrown when the + * meta data is invalid */ public function parseFileMeta($rawContent, array $headers) { @@ -955,12 +957,23 @@ class Pico $url = $this->getPageUrl($id); if ($file != $this->requestFile) { $rawContent = file_get_contents($file); - $meta = $this->parseFileMeta($rawContent, $this->getMetaHeaders()); + + $headers = $this->getMetaHeaders(); + try { + $meta = $this->parseFileMeta($rawContent, $headers); + } catch (\Symfony\Component\Yaml\Exception\ParseException $e) { + $meta = array_fill_keys(array_keys($headers), ''); + $meta['time'] = $meta['date_formatted'] = ''; + $meta['YAML_ParseError'] = $e->getMessage(); + } } else { $rawContent = &$this->rawContent; $meta = &$this->meta; } + // fallback to page id if page title is empty + $meta['title'] = (!empty($meta['title'])) ? $meta['title'] : $id; + // build page data // title, description, author and date are assumed to be pretty basic data // everything else is accessible through $page['meta'] From 3798cbe478b3bc3d4f8fdd9af3bf5a2b42e5545e Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Mon, 21 Dec 2015 04:05:25 +0100 Subject: [PATCH 2/3] Remove page title fallback --- lib/Pico.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/Pico.php b/lib/Pico.php index 3ea121b..6b0ef95 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -971,9 +971,6 @@ class Pico $meta = &$this->meta; } - // fallback to page id if page title is empty - $meta['title'] = (!empty($meta['title'])) ? $meta['title'] : $id; - // build page data // title, description, author and date are assumed to be pretty basic data // everything else is accessible through $page['meta'] From 43f953b67af22b084501b337010e0421a8745313 Mon Sep 17 00:00:00 2001 From: Daniel Rudolf Date: Mon, 21 Dec 2015 04:08:35 +0100 Subject: [PATCH 3/3] Pico::readPages(): Call Pico::parseFileMeta() again when a exception is thrown --- lib/Pico.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Pico.php b/lib/Pico.php index 6b0ef95..62174bf 100644 --- a/lib/Pico.php +++ b/lib/Pico.php @@ -962,8 +962,7 @@ class Pico try { $meta = $this->parseFileMeta($rawContent, $headers); } catch (\Symfony\Component\Yaml\Exception\ParseException $e) { - $meta = array_fill_keys(array_keys($headers), ''); - $meta['time'] = $meta['date_formatted'] = ''; + $meta = $this->parseFileMeta('', $headers); $meta['YAML_ParseError'] = $e->getMessage(); } } else {