Skip to content

Commit

Permalink
Merge pull request #25 from getherbie/Netzweberei-patch-1
Browse files Browse the repository at this point in the history
Ignore BOM in Page- and FrontMatterLoader
  • Loading branch information
tbreuss committed Jan 26, 2016
2 parents 7743d0b + edce26e commit 39fca40
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
8 changes: 6 additions & 2 deletions system/Loader/FrontMatterLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@ class FrontMatterLoader
*/
public function load($path)
{
if(!defined('UTF8_BOM')) {
define('UTF8_BOM', chr(0xEF).chr(0xBB).chr(0xBF));
}

$yaml = '';

$fileObject = new \SplFileObject($path);

$i = 0;
foreach ($fileObject as $line) {
// strip \n and \r from end of line
$line = rtrim($line, "\n\r");
// strip BOM from the beginning and \n and \r from end of line
$line = rtrim(ltrim($line, UTF8_BOM), "\n\r");
if (preg_match('/^---$/', $line)) {
$i++;
continue;
Expand Down
6 changes: 5 additions & 1 deletion system/Loader/PageLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@ public function save($alias, array $data = [], array $segments = [])
*/
protected function parseContent($content)
{
if(!defined('UTF8_BOM')) {
define('UTF8_BOM', chr(0xEF).chr(0xBB).chr(0xBF));
}

$yaml = '';
$segments = [];

$matched = preg_match('/^-{3}\r?\n(.*)\r?\n-{3}\R(.*)/ms', $content, $matches);
$matched = preg_match('/^['.UTF8_BOM.']*-{3}\r?\n(.*)\r?\n-{3}\R(.*)/ms', $content, $matches);

if ($matched === 1 && count($matches) == 3) {
$yaml = $matches[1];
Expand Down

0 comments on commit 39fca40

Please sign in to comment.