Skip to content

fix(scripts): handle CRLF line endings in frontmatter parser for Wind…#505

Open
Rajeevydvv wants to merge 2 commits into
krkn-chaos:mainfrom
Rajeevydvv:fix/crlf-frontmatter-parser
Open

fix(scripts): handle CRLF line endings in frontmatter parser for Wind…#505
Rajeevydvv wants to merge 2 commits into
krkn-chaos:mainfrom
Rajeevydvv:fix/crlf-frontmatter-parser

Conversation

@Rajeevydvv

Copy link
Copy Markdown
Contributor

Bug Fix

Related Feature:
fix/crlf-frontmatter-parser

Changes:

The frontmatter parser in scripts/build-search-index.js used
\n (Unix line endings) in both the regex and string split,
causing it to silently fail on Windows machines that use \r\n
(CRLF) line endings.

Root Cause:
Windows contributors cloning this repo get files with CRLF line
endings by default. The frontmatter regex /^---\n([\s\S]*?)\n---/
does not account for \r — so on Windows, the regex never matches,
frontmatter stays as {}, and every document gets indexed with
no title, no description, and incorrect content — silently breaking
the entire search index.

Before:

// ❌ Fails on Windows CRLF line endings
const frontmatterMatch = content.match(/^---\n([\s\S]*?)\n---/);
// ❌ Splits incorrectly — \r left in key/value strings
const yamlLines = frontmatterMatch[1].split('\n');

After:

// ✅ Handles both LF (Unix/macOS) and CRLF (Windows)
const frontmatterMatch = content.match(/^---\r?\n([\s\S]*?)\r?\n---/);
// ✅ Correctly splits on both line ending types
const yamlLines = frontmatterMatch[1].split(/\r?\n/);

Why this matters:

  • Windows contributors running npm run build or
    npm run build:search-index locally would get a completely
    broken search index with all documents showing as Untitled
  • The chatbot's documentation search quality degrades silently —
    no error is thrown, making this extremely hard to debug
  • \r?\n is the standard cross-platform fix — zero impact on
    Unix/macOS builds

This is a 2-line change with no impact on production Netlify
builds (which run on Linux) but fixes local development for
all Windows contributors.

@netlify

netlify Bot commented May 24, 2026

Copy link
Copy Markdown

Deploy Preview for krkn-chaos ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit e68e7ca
🔍 Latest deploy log https://app.netlify.com/projects/krkn-chaos/deploys/6a19d95b1c91780008f6c334
😎 Deploy Preview https://deploy-preview-505--krkn-chaos.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@qodo-code-review

Copy link
Copy Markdown

Review Summary by Qodo

Handle CRLF line endings in frontmatter parser

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Handle CRLF line endings in frontmatter regex pattern
• Split YAML lines using cross-platform regex pattern
• Fix silent search index corruption on Windows machines
• Clean up trailing whitespace throughout file
Diagram
flowchart LR
  A["Windows CRLF<br/>Line Endings"] -->|"Previously Failed"| B["Frontmatter Regex<br/>with \\n only"]
  B --> C["Silent Failure<br/>Empty Metadata"]
  C --> D["Broken Search Index"]
  A -->|"Now Fixed"| E["Frontmatter Regex<br/>with \\r?\\n"]
  E --> F["Correct Metadata<br/>Extraction"]
  F --> G["Valid Search Index"]

Loading

File Changes

1. scripts/build-search-index.js 🐞 Bug fix +20/-21

Fix CRLF line ending handling in frontmatter parser

• Updated frontmatter regex from /^---\n([\s\S]*?)\n---/ to /^---\r?\n([\s\S]*?)\r?\n---/ to
 handle both LF and CRLF line endings
• Changed YAML line splitting from .split('\n') to .split(/\r?\n/) for cross-platform
 compatibility
• Removed trailing whitespace from multiple blank lines throughout the file for consistent
 formatting

scripts/build-search-index.js


Grey Divider

Qodo Logo

@qodo-code-review

qodo-code-review Bot commented May 24, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Qodo Logo

@Rajeevydvv

Copy link
Copy Markdown
Contributor Author

Hi @paigerube14, could you please review this, open to any changes if needed.

…ows compatibility

Signed-off-by: Rajeev-Cryptographer <Rajeevofficial3@gmail.com>
Signed-off-by: Rajeev-Cryptographer <Rajeevofficial3@gmail.com>
@Rajeevydvv Rajeevydvv force-pushed the fix/crlf-frontmatter-parser branch from 30bd933 to e68e7ca Compare May 29, 2026 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant