Skip to content

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

Draft
lwshang wants to merge 2 commits into
lwshang/fix_payload_too_largefrom
lwshang/fix_comments_in_rules
Draft

fix(assets-sync): only treat # as a comment at line start or after whitespace#69
lwshang wants to merge 2 commits into
lwshang/fix_payload_too_largefrom
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 and others added 2 commits May 29, 2026 16:35
…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>
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