mirror of
https://github.com/gohugoio/hugo.git
synced 2025-05-01 16:10:07 +03:00
parser/pageparser: Fix handling of commented out front matter
When the page parser was rewritten in 0.51, this was interpreted literally, but commented out front matter is used in the wild to "hide it from GitHub", e.g: ``` <!-- +++ title = "hello" +++ --> ``` Fixes #5478
This commit is contained in:
parent
7e75aeca80
commit
7540a62834
6 changed files with 65 additions and 13 deletions
|
@ -60,7 +60,8 @@ var frontMatterTests = []lexerTest{
|
|||
{"No front matter", "\nSome text.\n", []Item{tstSomeText, tstEOF}},
|
||||
{"YAML front matter", "---\nfoo: \"bar\"\n---\n\nSome text.\n", []Item{tstFrontMatterYAML, tstSomeText, tstEOF}},
|
||||
{"YAML empty front matter", "---\n---\n\nSome text.\n", []Item{nti(TypeFrontMatterYAML, ""), tstSomeText, tstEOF}},
|
||||
{"YAML commented out front matter", "<!--\n---\nfoo: \"bar\"\n---\n-->\nSome text.\n", []Item{nti(TypeHTMLComment, "<!--\n---\nfoo: \"bar\"\n---\n-->"), tstSomeText, tstEOF}},
|
||||
{"YAML commented out front matter", "<!--\n---\nfoo: \"bar\"\n---\n-->\nSome text.\n", []Item{nti(TypeIgnore, "<!--\n"), tstFrontMatterYAML, nti(TypeIgnore, "-->"), tstSomeText, tstEOF}},
|
||||
{"YAML commented out front matter, no end", "<!--\n---\nfoo: \"bar\"\n---\nSome text.\n", []Item{nti(TypeIgnore, "<!--\n"), tstFrontMatterYAML, nti(tError, "starting HTML comment with no end")}},
|
||||
// Note that we keep all bytes as they are, but we need to handle CRLF
|
||||
{"YAML front matter CRLF", "---\r\nfoo: \"bar\"\r\n---\n\nSome text.\n", []Item{tstFrontMatterYAMLCRLF, tstSomeText, tstEOF}},
|
||||
{"TOML front matter", "+++\nfoo = \"bar\"\n+++\n\nSome text.\n", []Item{tstFrontMatterTOML, tstSomeText, tstEOF}},
|
||||
|
@ -78,7 +79,6 @@ var frontMatterTests = []lexerTest{
|
|||
func TestFrontMatter(t *testing.T) {
|
||||
t.Parallel()
|
||||
for i, test := range frontMatterTests {
|
||||
|
||||
items := collect([]byte(test.input), false, lexIntroSection)
|
||||
if !equal(items, test.items) {
|
||||
got := crLfReplacer.Replace(fmt.Sprint(items))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue