Thanks to visit codestin.com
Credit goes to github.com

Skip to content

UTF-8 with BOM #461

@fl3pp

Description

@fl3pp

Hello together,

Unfortunately Pico didn't render my YAML content correctly. I was searching several hours until I found the issue in the regex:

$markdown = preg_replace($metaHeaderPattern, '', $rawContent, 1);

I was able to reproduce the problem in a small script:

$metaHeaderPattern = "/^(\/(\*)|---)[[:blank:]]*(?:\r)?\n"
. "(?:(.*?)(?:\r)?\n)?(?(2)\*\/|---)[[:blank:]]*(?:(?:\r)?\n|$)/s";

// returns false
$rawContent = file_get_contents("C:\FILE WITH BOM");
$isMatch = preg_match($metaHeaderPattern, $rawContent) == 1;

// return true
$rawContent = file_get_contents("C:\FILE WITHOUT BOM");
$isMatch = preg_match($metaHeaderPattern, $rawContent) == 1;

It seems that the regex replacement (and the markdown parsing too) is not able to handle files with UTF-8 BOM headers correctly.
One should not add BOMs anyway, but many text-editor do without users knowing it.

Could you add support for BOMs?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions