Skip to content

[workers-shared] Add support for inline comments in _redirects files#12467

Merged
petebacondarwin merged 5 commits intomainfrom
fix/3255-inline-comments-redirects
Feb 9, 2026
Merged

[workers-shared] Add support for inline comments in _redirects files#12467
petebacondarwin merged 5 commits intomainfrom
fix/3255-inline-comments-redirects

Conversation

@petebacondarwin
Copy link
Copy Markdown
Contributor

@petebacondarwin petebacondarwin commented Feb 7, 2026

Fixes #3255.

Adds support for inline comments in _redirects files using the # character. This allows developers to document complex redirect rules directly alongside the rules themselves:

/old-page /new-page 301 # Moved during site redesign
/blog/* /articles/:splat # Blog URL migration

The implementation detects inline comments by looking for any token starting with # at position 2 or later (after the required from and to tokens). This approach:

  • Correctly preserves URL fragments like /page#section (no space before the #)
  • Strips comments like /a /b # comment or /a /b 301 # comment
  • Is backwards compatible - existing _redirects files work identically
  • Handles edge cases like empty comments, multiple hashes in fragments, and absolute URLs with fragments

A picture of a cute animal (not mandatory, but encouraged)


Open with Devin

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Feb 7, 2026

🦋 Changeset detected

Latest commit: d075084

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@claude
Copy link
Copy Markdown
Contributor

claude Bot commented Feb 7, 2026

Claude finished @petebacondarwin's task —— View job


Changeset Review

Reviewing the changeset for this PR...

Tasks

  • Read changeset guidelines from .changeset/README.md
  • Review .changeset/inline-comments-redirects.md
  • Validate version type, changelog quality, and formatting
  • Check for cute animal images
  • Post review findings

Review Results

All changesets look good

The changeset .changeset/inline-comments-redirects.md is well-formatted and follows all guidelines:

  • Version Type: minor is appropriate (new feature - inline comment support)
  • Changelog Quality: Clear title and helpful body with usage examples
  • Markdown Headers: No h1/h2/h3 headers used ✓
  • Package Coverage: Correctly references @cloudflare/workers-shared
  • Description: Excellent - explains what the feature is, provides examples, and notes important details about URL fragments

The changeset effectively communicates the new functionality and will create a helpful changelog entry for users.


@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Feb 7, 2026

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@12467

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@12467

miniflare

npm i https://pkg.pr.new/miniflare@12467

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@12467

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@12467

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@12467

@cloudflare/vitest-pool-workers

npm i https://pkg.pr.new/@cloudflare/vitest-pool-workers@12467

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@12467

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@12467

wrangler

npm i https://pkg.pr.new/wrangler@12467

commit: d075084

@petebacondarwin
Copy link
Copy Markdown
Contributor Author

The docs already state:

Lines starting with a # will be treated as comments.

I think we probably need to tweak those to also cover these new inline comments.

@petebacondarwin petebacondarwin marked this pull request as ready for review February 7, 2026 15:20
@petebacondarwin petebacondarwin requested review from a team as code owners February 7, 2026 15:20
@petebacondarwin petebacondarwin added internal Requires support from the Cloudflare Platform Workers + Assets labels Feb 7, 2026
@petebacondarwin
Copy link
Copy Markdown
Contributor Author

The change is in workers-shared, which is used in the backend to parse the _redirects file at deploy/runtime.
Once we land this change it won't be live in production until the backend updates its version of workers-shared.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 4 additional findings.

Open in Devin Review

@github-project-automation github-project-automation Bot moved this from Untriaged to Approved in workers-sdk Feb 7, 2026
Allow inline comments in redirect rules using the # character:
/old-page /new-page 301 # Moved during site redesign

URL fragments (e.g., /page#section) are preserved correctly since
comments are only detected after the from and to tokens.

Fixes #3255
Additional test coverage for:
- Single comment-only line
- Indented comment-only line
- Multiple consecutive comment lines mixed with rules
- File containing only comments (no redirect rules)
@petebacondarwin petebacondarwin force-pushed the fix/3255-inline-comments-redirects branch from 9c1994f to c744eef Compare February 8, 2026 14:11
vicb
vicb previously requested changes Feb 8, 2026
Copy link
Copy Markdown
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

See the inline comment

Comment thread packages/workers-shared/utils/configuration/parseRedirects.ts Outdated
@github-project-automation github-project-automation Bot moved this from Approved to In Review in workers-sdk Feb 8, 2026
Comment thread packages/workers-shared/utils/configuration/parseRedirects.ts Outdated
Comment thread packages/workers-shared/utils/tests/parseRedirects.valid.test.ts Outdated
@petebacondarwin petebacondarwin requested a review from vicb February 8, 2026 18:03
Comment thread packages/workers-shared/utils/configuration/parseRedirects.ts Outdated
Comment thread packages/workers-shared/utils/configuration/parseRedirects.ts
@petebacondarwin petebacondarwin dismissed vicb’s stale review February 9, 2026 11:23

Feedback addressed.

@petebacondarwin petebacondarwin merged commit 7036310 into main Feb 9, 2026
47 checks passed
@petebacondarwin petebacondarwin deleted the fix/3255-inline-comments-redirects branch February 9, 2026 11:23
@github-project-automation github-project-automation Bot moved this from In Review to Done in workers-sdk Feb 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Requires support from the Cloudflare Platform Workers + Assets

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

🚀 Feature Request: Allow inline comments on redirects

4 participants