From ab0145dd0e3b28f3aa3d6ddc0f3711e2d255c008 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 1 Sep 2026 00:35:30 +0000 Subject: [PATCH] Fix FrontMatterFile.ParseFromLines truncating values containing colons Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- RELEASE_NOTES.md | 3 +++ src/FSharp.Formatting.Common/Templating.fs | 2 +- .../FSharp.Literate.Tests/DocContentTests.fs | 21 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 3e1b18091..2986322cf 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -5,6 +5,9 @@ ### Changed * Rewrote the Mermaid documentation recipe as `docs/mermaid.md` (moved from the oddly-named `docs/sidebyside/sidemermaid.md`) to follow the approach used by the fantomas docs: diagrams are written as plain ```mermaid fenced code blocks, which GitHub renders natively, and an `_body.html` script promotes those blocks into `
` elements on fsdocs pages. The FSharp.Formatting docs now ship that script (`docs/_body.html`), so the recipe page actually demonstrates working diagrams. +### Fixed +* Fix `FrontMatterFile.ParseFromLines` truncating front-matter values that contain a `:` character (e.g. `title: F#: An Introduction` was previously captured as just `F#`). Additional colons in a value are now preserved. + ## [22.2.0] - 2026-08-31 ### Changed diff --git a/src/FSharp.Formatting.Common/Templating.fs b/src/FSharp.Formatting.Common/Templating.fs index 0b83593ad..1183ea2cb 100644 --- a/src/FSharp.Formatting.Common/Templating.fs +++ b/src/FSharp.Formatting.Common/Templating.fs @@ -53,7 +53,7 @@ type FrontMatterFile = let parts = line.Split(":") |> Array.toList match parts with - | first :: second :: _ -> Some(first.ToLowerInvariant(), second) + | first :: rest when not rest.IsEmpty -> Some(first.ToLowerInvariant(), String.Join(":", rest)) | _ -> None else None) diff --git a/tests/FSharp.Literate.Tests/DocContentTests.fs b/tests/FSharp.Literate.Tests/DocContentTests.fs index 5f706abdd..94d4ba2e6 100644 --- a/tests/FSharp.Literate.Tests/DocContentTests.fs +++ b/tests/FSharp.Literate.Tests/DocContentTests.fs @@ -745,3 +745,24 @@ let ``LlmsTxt collapses excessive blank lines in content`` () = llmsFullTxt.Contains("\n\n\n") |> shouldEqual false llmsFullTxt |> shouldContainText "First paragraph" llmsFullTxt |> shouldContainText "Second paragraph" + +// -------------------------------------------------------------------------------------- +// Tests for FrontMatterFile.ParseFromLines +// -------------------------------------------------------------------------------------- + +[] +let ``ParseFromLines preserves colons in front-matter values`` () = + let lines = [ "---"; "title: F#: An Introduction"; "category: Guides"; "categoryindex: 2"; "index: 1"; "---" ] + + match FrontMatterFile.ParseFromLines "test.md" lines with + | Some frontMatter -> + frontMatter.Category |> shouldEqual "Guides" + frontMatter.CategoryIndex |> shouldEqual 2 + frontMatter.Index |> shouldEqual 1 + | None -> failwith "Expected front matter to be parsed" + +[] +let ``ParseFromLines returns None when required fields are missing`` () = + let lines = [ "---"; "title: No Category Here"; "---" ] + + FrontMatterFile.ParseFromLines "test.md" lines |> shouldEqual None