Skip to content

fix: validate invalid blog post dates - #280

Open
samc4e wants to merge 8 commits into
webpack:mainfrom
samc4e:fix/validate-blog-post-dates
Open

samc4e wants to merge 8 commits into
webpack:mainfrom
samc4e:fix/validate-blog-post-dates

Conversation

@samc4e

@samc4e samc4e commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

fixes: #279

Summary

Fix blog date validation during documentation builds.

JavaScript can normalize invalid dates such as 2026-02-30(30 days in feb is incorrect date) into a different valid date instead of rejecting them. This could allow incorrect blog metadata to pass through the build.

This change validates the calendar date and time components before generating blog data. Invalid values now fail with an error that includes the affected file and date value.

What kind of change does this PR introduce?

Bug fix and test improvement.


Did you add tests for your changes?

Yes. Tests cover:

  • Invalid calendar dates such as 2026-02-30
  • One-digit date fields that roll over
  • Invalid hour, minute, and second values
  • Missing and malformed dates
  • Error messages containing the file path and invalid value

Does this PR introduce a breaking change?

No. Valid blog dates continue to work as before. Dates that were previously accepted and normalized incorrectly are now rejected during the build.


The following demonstrates the incorrect blog post date behavior:

Incorrect blog post date

Before

Before

After

Invalid dates are rejected with a clear validation error identifying the file and value.

After


If relevant, what needs to be documented once your changes are merged or what have you already documented?

No documentation required.

Use of AI
AI was used during investigation and implementation review. The changes and test results were reviewed locally.

Summary by CodeRabbit

  • Bug Fixes
    • Blog post dates are now validated before posts are created. Invalid or missing dates produce an error that identifies the Markdown file and supplied date.
    • Valid dates are consistently serialized in ISO format.

@vercel

vercel Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
webpack-doc-kit Ready Ready Preview Oct 25, 2026 7:04pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 48 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8ea19754-769d-4c93-a03c-6063d08a9586
Commits

Reviewing files that changed from the base of the PR and between bd48f5d and a444680.

Files selected for processing: 1
  • scripts/data/blog.mjs

Walkthrough

The blog data generator parses each post date once before building the post object. Invalid or missing dates now cause an error that identifies the Markdown file and supplied value. Valid dates are stored as ISO strings.

Priority: Normal

Severity of issue fixed: Medium

Merge Risk: Moderate · up to bd48f

The blog build can still succeed with an invalid calendar date or a missing date and publish an incorrect date. Fix both validation gaps before merging.

Architecture risk: Low · up to d72f4

The change affects 2 systems.

Changed systems: scripts, tests

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — scripts (service) was modified; 1 changed file maps to changed impact.
  • observed — tests (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in scripts/data/blog.mjs: Added parseDate, which throws a file-specific error for missing or invalid dates and returns valid dates as ISO strings.
  • observed — Modified behavior in scripts/data/blog.mjs: readPosts now passes the frontmatter date and filename to parseDate instead of directly converting the date to an ISO string.
  • observed — Modified behavior in tests/data/blog.test.mjs: Adds imports and helpers to create a temporary blog fixture with a copied script and post, then execute the script in that fixture.
  • observed — Modified behavior in tests/data/blog.test.mjs: Adds a test that runs the script with a valid date and checks that generated blog JSON contains the corresponding ISO timestamp.
Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Linked Issues check Warning Issue #279 requires rejection of nonexistent calendar dates and invalid time values without silent normalization. In scripts/data/blog.mjs, the current code only checks `new Date(data.date).getTime(… Validate the date format and each calendar and time component before converting the value to an ISO string. Keep the error message tied to the post file and supplied value. Add automated tests for valid dates, missing and malformed values, …
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix: validate invalid blog post dates" matches the main change. The raw summary says blog post dates are now parsed and validated, and an error names the Markdown file and invalid date when…
Out of Scope Changes check Passed The reviewable change is limited to blog frontmatter date handling in scripts/data/blog.mjs. This implements the build-tooling scope of issue #279. No unrelated production or test changes are establ…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Title check

Explanation

The title "fix: validate invalid blog post dates" matches the main change. The raw summary says blog post dates are now parsed and validated, and an error names the Markdown file and invalid date when a date is invalid or missing. The PR objectives confirm the same goal: validating blog date components before generating blog data, with errors that identify the file and value. The title is specific and concise, and it follows the conventional commit style. It does not cover the ISO serialization or the missing-date handling, but that is expected for a short title.

Full details: Out of Scope Changes check

Explanation

The reviewable change is limited to blog frontmatter date handling in scripts/data/blog.mjs. This implements the build-tooling scope of issue #279. No unrelated production or test changes are established by the available evidence.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.

Full details: Linked Issues check

Explanation

Issue #279 requires rejection of nonexistent calendar dates and invalid time values without silent normalization. In scripts/data/blog.mjs, the current code only checks new Date(data.date).getTime(). JavaScript can normalize values such as 2026-02-30, so the build can still generate incorrect blog data. The reviewed files also show no blog-date test file or test change that verifies the required calendar and time cases.

Resolution

Validate the date format and each calendar and time component before converting the value to an ISO string. Keep the error message tied to the post file and supplied value. Add automated tests for valid dates, missing and malformed values, nonexistent dates such as 2026-02-30, invalid times, and the required error context.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 18bd59e9-472c-4ce6-8c08-c722f3431188

📥 Commits

Reviewing files that changed from the base of the PR and between 047f2d0 and 10e985d.

📒 Files selected for processing (2)
  • scripts/data/blog.mjs
  • tests/data/blog.test.mjs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread scripts/data/blog.mjs Outdated
@avivkeller

Copy link
Copy Markdown
Member

Rather than this, can't we just edit the blog posts to have the right dates?

@samc4e

samc4e commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor Author

Rather than this, can't we just edit the blog posts to have the right dates?

yes true I thought on this ,that dev should write valid blog dates. I just added validation as fallback bcoz invalid dates and incorrect format previously allowed the build to succeed with incorrect data.Now It provides an early, clear error, as I pasted img of before after in decription , If this not still needed I'll work to other area by closing this...

@avivkeller

Copy link
Copy Markdown
Member

This just seems awfully complex for something that (should be, if it were to exist) fairly simple

@samc4e

samc4e commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

Understood. , if I find any other optimal way I will continue with this ...otherwise avoids adding unnecessary build logic and will close pr , thanks for the feedback.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 3882d858-3d2c-49b9-b01f-a8cbb7c6f9ce
📥 Commits

Reviewing files that changed from the base of the PR and between 10e985d and d72f4b5.

📒 Files selected for processing (2)
  • scripts/data/blog.mjs
  • tests/data/blog.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread scripts/data/blog.mjs Outdated
@samc4e
samc4e force-pushed the fix/validate-blog-post-dates branch 2 times, most recently from 57a3cda to d72f4b5 Compare October 3, 2026 23:24
@github-actions github-actions Bot removed the tests Pull requests that update tests label Oct 25, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


Review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0f425244-ccb6-4906-aee6-00d47d601b33
Commits

Reviewing files that changed from the base of the PR and between d72f4b5 and bd48f5d.

Files selected for processing: 1
  • scripts/data/blog.mjs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Comment thread scripts/data/blog.mjs Outdated
@samc4e

samc4e commented Oct 25, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback @avivkeller @moshams272 . I've cut this down to a single check in scripts/data/blog.mjs and removed the tests.

Before: a missing or malformed date crashed the build with RangeError: Invalid time value, without naming the post. Empty or non-date values (date:, 0, true) were silently written as 1970-01-01.
Now: only unquoted YAML dates are accepted, which all current posts already use. Anything else fails with Invalid or missing date in .md: .

Existing posts build with identical output. Impossible dates like 2026-02-30 are still out of scope, since the YAML parser rolls them over before this code runs. If you'd rather not have this check, I'm happy to close the PR.

This branch was successfully deployed

1 active deployment
Preview — a4446801 Deployed Oct 25, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(build): validate blog post dates during data generation

2 participants