Implement our own RFC 6570 URI Template expansion and pattern matching to ensure symmetric behavior and eliminate dependency on third-party libraries with asymmetric implementations.
Background
Currently, Fedify relies on:
This leads to issues like #416 where expansion and parsing don't round-trip correctly, causing:
- Inconsistent encoding/decoding behavior
- Double-encoding problems in collections
- Unpredictable results for users
The asymmetric behavior is documented in uri-template-router issue #11.
Problem with current approach
The fundamental issue is that RFC 6570 only defines expansion behavior, not pattern matching. uri-template-router implements pattern matching as an extension, but this creates asymmetry:
Value → url-template (expand) → URL → uri-template-router (parse) → Different value
Proposed solution
Implement a custom RFC 6570 library that provides:
Core features
- Expansion: Full RFC 6570 compliance for all expression types
- Symmetric pattern matching: Custom implementation that guarantees round-trip consistency
- Type safety: Better TypeScript integration than current libraries
Expression types to support
{var}: Simple string expansion
{+var}: Reserved string expansion
{/var}: Path segment expansion
{?var}: Query parameter expansion
{&var}: Query continuation expansion
{#var}: Fragment expansion
Benefits
- Guaranteed symmetry:
expand(parse(url)) === url and parse(expand(value)) === value
- Predictable behavior: Eliminates current inconsistencies
- Reduced dependencies: Remove url-template and uri-template-router
- Fedify-optimized: Can add ActivityPub-specific optimizations if needed
Implementation plan
Phase 1: RFC 6570 expansion
Phase 2: Symmetric pattern matching
Phase 3: Integration
Phase 4: Documentation
Considerations
- Scope: This is a significant undertaking that essentially creates a new library
- Timeline: Should be treated as a long-term goal, not urgent
- Compatibility: Must maintain backward compatibility with existing Fedify APIs
- Testing: Requires extensive testing against RFC 6570 spec and real-world usage
Alternative approaches
- Contribute fixes to uri-template-router (but maintainer may not accept due to breaking changes)
- Find alternative libraries with symmetric behavior (research needed)
- Live with current limitations and document workarounds
Implement our own RFC 6570 URI Template expansion and pattern matching to ensure symmetric behavior and eliminate dependency on third-party libraries with asymmetric implementations.
Background
Currently, Fedify relies on:
This leads to issues like #416 where expansion and parsing don't round-trip correctly, causing:
The asymmetric behavior is documented in uri-template-router issue #11.
Problem with current approach
The fundamental issue is that RFC 6570 only defines expansion behavior, not pattern matching. uri-template-router implements pattern matching as an extension, but this creates asymmetry:
Proposed solution
Implement a custom RFC 6570 library that provides:
Core features
Expression types to support
{var}: Simple string expansion{+var}: Reserved string expansion{/var}: Path segment expansion{?var}: Query parameter expansion{&var}: Query continuation expansion{#var}: Fragment expansionBenefits
expand(parse(url)) === urlandparse(expand(value)) === valueImplementation plan
Phase 1: RFC 6570 expansion
Phase 2: Symmetric pattern matching
Phase 3: Integration
Phase 4: Documentation
Considerations
Alternative approaches