Support content files with UTF-8 BOM

Resolves #461
pico-3.0-alpha
Daniel Rudolf 6 years ago
parent d95c9d3708
commit 1d5aba46af
No known key found for this signature in database
GPG Key ID: A061F02CD8DE4538
  1. 4
      lib/Pico.php

@ -1477,7 +1477,7 @@ class Pico
public function parseFileMeta($rawContent, array $headers) public function parseFileMeta($rawContent, array $headers)
{ {
$meta = array(); $meta = array();
$pattern = "/^(\/(\*)|---)[[:blank:]]*(?:\r)?\n" $pattern = "/^(?:\xEF\xBB\xBF)?(\/(\*)|---)[[:blank:]]*(?:\r)?\n"
. "(?:(.*?)(?:\r)?\n)?(?(2)\*\/|---)[[:blank:]]*(?:(?:\r)?\n|$)/s"; . "(?:(.*?)(?:\r)?\n)?(?(2)\*\/|---)[[:blank:]]*(?:(?:\r)?\n|$)/s";
if (preg_match($pattern, $rawContent, $rawMetaMatches) && isset($rawMetaMatches[3])) { if (preg_match($pattern, $rawContent, $rawMetaMatches) && isset($rawMetaMatches[3])) {
$meta = $this->getYamlParser()->parse($rawMetaMatches[3]) ?: array(); $meta = $this->getYamlParser()->parse($rawMetaMatches[3]) ?: array();
@ -1581,7 +1581,7 @@ class Pico
public function prepareFileContent($rawContent, array $meta = array()) public function prepareFileContent($rawContent, array $meta = array())
{ {
// remove meta header // remove meta header
$metaHeaderPattern = "/^(\/(\*)|---)[[:blank:]]*(?:\r)?\n" $metaHeaderPattern = "/^(?:\xEF\xBB\xBF)?(\/(\*)|---)[[:blank:]]*(?:\r)?\n"
. "(?:(.*?)(?:\r)?\n)?(?(2)\*\/|---)[[:blank:]]*(?:(?:\r)?\n|$)/s"; . "(?:(.*?)(?:\r)?\n)?(?(2)\*\/|---)[[:blank:]]*(?:(?:\r)?\n|$)/s";
$markdown = preg_replace($metaHeaderPattern, '', $rawContent, 1); $markdown = preg_replace($metaHeaderPattern, '', $rawContent, 1);

Loading…
Cancel
Save