[workers-shared] Add support for inline comments in _redirects files#12467
[workers-shared] Add support for inline comments in _redirects files#12467petebacondarwin merged 5 commits intomainfrom
Conversation
🦋 Changeset detectedLatest 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 finished @petebacondarwin's task —— View job Changeset ReviewReviewing the changeset for this PR... Tasks
Review Results✅ All changesets look good The changeset
The changeset effectively communicates the new functionality and will create a helpful changelog entry for users. |
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
|
The docs already state:
I think we probably need to tweak those to also cover these new inline comments. |
|
The change is in workers-shared, which is used in the backend to parse the _redirects file at deploy/runtime. |
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)
9c1994f to
c744eef
Compare
Co-authored-by: Victor Berchet <victor@suumit.com>
Fixes #3255.
Adds support for inline comments in
_redirectsfiles using the#character. This allows developers to document complex redirect rules directly alongside the rules themselves:The implementation detects inline comments by looking for any token starting with
#at position 2 or later (after the requiredfromandtotokens). This approach:/page#section(no space before the#)/a /b # commentor/a /b 301 # comment_redirectsfiles work identically_redirectsfiles cloudflare-docs#28171A picture of a cute animal (not mandatory, but encouraged)