Skip to content

fix(hls): resolve root-relative and protocol-relative playlist URIs - #184

Open
HEOJUNFO wants to merge 1 commit into
OpenSelena:devfrom
HEOJUNFO:fix/hls-root-relative-uri
Open

HEOJUNFO wants to merge 1 commit into
OpenSelena:devfrom
HEOJUNFO:fix/hls-root-relative-uri

Conversation

@HEOJUNFO

@HEOJUNFO HEOJUNFO commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

resolve_url in the HLS downloader joined every non-absolute URI onto the playlist's directory. Two valid forms came out wrong:

Playlist URI in the playlist Before After
https://cdn.example.com/path/master.m3u8 /hls/v1/seg0.ts https://cdn.example.com/path//hls/v1/seg0.ts https://cdn.example.com/hls/v1/seg0.ts
https://cdn.example.com/path/master.m3u8 //cdn2.example.com/seg0.ts https://cdn.example.com/path///cdn2.example.com/seg0.ts https://cdn2.example.com/seg0.ts

The same function resolves segments, the variant playlist picked from a master, and AES key URIs, so a playlist that uses either form fails at whichever of those it hits first.

  • Root-relative URIs resolve against the playlist's origin (url_origin, already in this file) and keep the playlist's query string, like other relative segments do.
  • Protocol-relative URIs take the playlist's scheme and no query, like absolute URLs.

Plain relative and absolute URIs are unchanged; the existing tests cover those.

Tested with cargo test -p libreget-core --lib hls_downloader (40 passed). The three new tests fail on dev with the "Before" values above. cargo fmt --check is clean and clippy reports nothing in this file. I did not run a download against a live playlist that uses these forms.

🤖 Generated with Claude Code

resolve_url joined every non-absolute URI onto the playlist's directory,
so a root-relative segment (/hls/v1/seg0.ts) became
https://host/path//hls/v1/seg0.ts and a protocol-relative one
(//cdn2.host/seg0.ts) became https://host/path///cdn2.host/seg0.ts.
Both are valid in a playlist (RFC 8216 4.1 resolves URIs per RFC 3986),
and the same function resolves variant playlists and AES key URIs.

Root-relative URIs now resolve against the playlist's origin and keep
the playlist's query, like other relative segments. Protocol-relative
URIs take the playlist's scheme and no query, like absolute ones.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@HEOJUNFO
HEOJUNFO force-pushed the fix/hls-root-relative-uri branch from d184001 to ceb805f Compare November 15, 2026 05:20

This branch has not been deployed

No deployments
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