Skip to content

fix(assets-sync): only treat # as a comment at line start or after whitespace#69

Merged
lwshang merged 2 commits into
mainfrom
lwshang/fix_comments_in_rules
Jun 1, 2026
Merged

fix(assets-sync): only treat # as a comment at line start or after whitespace#69
lwshang merged 2 commits into
mainfrom
lwshang/fix_comments_in_rules

Conversation

@lwshang
Copy link
Copy Markdown
Collaborator

@lwshang lwshang commented May 29, 2026

Summary

  • Previous _redirects / _headers parsers cut every line at the first #, which corrupted URL fragments such as /to/#topic in a redirect target or report-uri /csp#endpoint in a CSP header value.
  • New shared strip_comment helper in assets-sync/src/lib.rs matches Netlify's reference parser: a # only begins a comment when it sits at the start of the line or is preceded by ASCII whitespace, so a # embedded inside a token is preserved.
  • De-duplicates the helper out of both redirects.rs and headers.rs.
  • Parse errors now embed the offending source line (e.g. _redirects: line 71: expected '<from> <to> <status>' (3 fields), got 2 (source: \/incomplete /target`)`) so users don't have to count lines to find the bad entry.

Supersedes #67 (thanks @raymondk for spotting the bug). The token-aware rule is a strict superset of Cloudflare's documented "lines starting with #" behaviour, so files written for either platform keep working.

Test plan

  • cargo test -p assets-sync — 187 tests pass, including new coverage for: fragment in redirect to, fragment in CSP header value, tab-preceded #, source-line embedded in parse errors, and the 6 strip_comment unit tests in lib.rs.
  • cargo clippy -p assets-sync --all-targets -- -D warnings clean.

🤖 Generated with Claude Code

@lwshang lwshang force-pushed the lwshang/fix_payload_too_large branch from ddc9077 to 0cc61e0 Compare June 1, 2026 20:00
lwshang and others added 2 commits June 1, 2026 16:06
…whitespace

Previously the `_redirects` and `_headers` parsers cut every line at the
first `#`, which corrupted URL fragments such as `/to/#topic` and CSP
`report-uri /csp#endpoint`. The new shared `strip_comment` in `lib.rs`
matches Netlify's reference parser: a `#` only begins a comment when it
sits at the start of the line or is preceded by ASCII whitespace, so a
`#` embedded inside a token is preserved.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…rors

A bare line number forces users to count down the file to find the bad
rule. Embedding the offending line in the error message makes it
obvious which entry to fix.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@lwshang lwshang marked this pull request as ready for review June 1, 2026 20:06
@lwshang lwshang requested a review from a team as a code owner June 1, 2026 20:06
@lwshang lwshang changed the base branch from lwshang/fix_payload_too_large to main June 1, 2026 20:06
@lwshang lwshang force-pushed the lwshang/fix_comments_in_rules branch from 7571cba to 0fd1868 Compare June 1, 2026 20:06
@lwshang lwshang enabled auto-merge (squash) June 1, 2026 20:06
@lwshang lwshang merged commit b43d8db into main Jun 1, 2026
11 checks passed
@lwshang lwshang deleted the lwshang/fix_comments_in_rules branch June 1, 2026 20:38
@lwshang lwshang restored the lwshang/fix_comments_in_rules branch June 1, 2026 20:38
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.

2 participants