From 6f981f7b749bd6d711f0cd67cb9be605faf4636a Mon Sep 17 00:00:00 2001 From: Jakub Olejnik Date: Wed, 4 Nov 2026 17:36:56 +0100 Subject: [PATCH 1/3] Keep query string when resolving relative playlist URIs getFullURL built absolute URLs for relative URIs with appendingPathComponent. That method percent-encodes '?' into '%3F', so a variant URI such as 'video.m3u8?hdntl=...' became part of the path and the server returned HTTP 400. Resolve the URI against the manifest URL with URL(string:relativeTo:) instead. Fall back to the previous behavior when that fails. --- .../Parsers/PlaylistParser.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Code/Sideloaded-TextTracks/Sources/THEOplayerConnectorSideloadedSubtitle/Parsers/PlaylistParser.swift b/Code/Sideloaded-TextTracks/Sources/THEOplayerConnectorSideloadedSubtitle/Parsers/PlaylistParser.swift index aad3cf55..f635a0ba 100644 --- a/Code/Sideloaded-TextTracks/Sources/THEOplayerConnectorSideloadedSubtitle/Parsers/PlaylistParser.swift +++ b/Code/Sideloaded-TextTracks/Sources/THEOplayerConnectorSideloadedSubtitle/Parsers/PlaylistParser.swift @@ -61,9 +61,15 @@ class PlaylistParser { url = URL(string: trimmedPath) } if let createdUrl = url, - createdUrl.scheme == nil, - let decodedPath = trimmedPath.removingPercentEncoding { // drop the percentEncoding as this will be reapplied by appendingPathComponent - return self.manifestURL.deletingLastPathComponent().appendingPathComponent(decodedPath) + createdUrl.scheme == nil { + // Resolve against the manifest URL so a query string (e.g. `?hdntl=...`) stays a query + // instead of being percent-encoded into the path by `appendingPathComponent`. + if let resolvedUrl = URL(string: trimmedPath, relativeTo: self.manifestURL)?.absoluteURL { + return resolvedUrl + } + if let decodedPath = trimmedPath.removingPercentEncoding { // drop the percentEncoding as this will be reapplied by appendingPathComponent + return self.manifestURL.deletingLastPathComponent().appendingPathComponent(decodedPath) + } } return url From 085f3d063edae61cb52b423ea2db06e40d8ea98c Mon Sep 17 00:00:00 2001 From: Jakub Olejnik Date: Thu, 5 Nov 2026 00:57:28 +0100 Subject: [PATCH 2/3] Add tests for resolving relative playlist URIs Cover relative URIs with a query string in the same directory, in a subdirectory and in a parent directory, a relative URI without a query, and an absolute URI. A relative URI without its own query does not get the playlist's query, as RFC 3986 section 5.2.2 specifies. --- .../PlaylistParserTests.swift | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 Code/Sideloaded-TextTracks/Tests/THEOplayerConnectorSideloadedSubtitleTests/PlaylistParserTests.swift diff --git a/Code/Sideloaded-TextTracks/Tests/THEOplayerConnectorSideloadedSubtitleTests/PlaylistParserTests.swift b/Code/Sideloaded-TextTracks/Tests/THEOplayerConnectorSideloadedSubtitleTests/PlaylistParserTests.swift new file mode 100644 index 00000000..afc06e91 --- /dev/null +++ b/Code/Sideloaded-TextTracks/Tests/THEOplayerConnectorSideloadedSubtitleTests/PlaylistParserTests.swift @@ -0,0 +1,47 @@ +import Foundation +import XCTest +@testable import THEOplayerConnectorSideloadedSubtitle + +final class PlaylistParserTests: XCTestCase { + private let manifestURL = URL(string: "https://cdn.example.com/vod/movie/index.m3u8?token=abc")! + + func testRelativeURIKeepsQueryString() { + let parser = PlaylistParser(url: manifestURL, request: nil) + + let url = parser.getFullURL(from: "video=391132.m3u8?hdntl=st=1~exp=2~acl=/*~hmac=ff") + + XCTAssertEqual(url?.absoluteString, "https://cdn.example.com/vod/movie/video=391132.m3u8?hdntl=st=1~exp=2~acl=/*~hmac=ff") + } + + func testRelativeURIInSubdirectoryKeepsQueryString() { + let parser = PlaylistParser(url: manifestURL, request: nil) + + let url = parser.getFullURL(from: "keyframes/video.m3u8?accountId=1") + + XCTAssertEqual(url?.absoluteString, "https://cdn.example.com/vod/movie/keyframes/video.m3u8?accountId=1") + } + + func testRelativeURIInParentDirectoryKeepsQueryString() { + let parser = PlaylistParser(url: manifestURL, request: nil) + + let url = parser.getFullURL(from: "../other/video.m3u8?accountId=1") + + XCTAssertEqual(url?.absoluteString, "https://cdn.example.com/vod/other/video.m3u8?accountId=1") + } + + func testRelativeURIWithoutQueryIsResolvedAgainstManifestDirectory() { + let parser = PlaylistParser(url: manifestURL, request: nil) + + let url = parser.getFullURL(from: "video.m3u8") + + XCTAssertEqual(url?.absoluteString, "https://cdn.example.com/vod/movie/video.m3u8") + } + + func testAbsoluteURIIsNotChanged() { + let parser = PlaylistParser(url: manifestURL, request: nil) + + let url = parser.getFullURL(from: "https://other.example.com/video.m3u8?token=xyz") + + XCTAssertEqual(url?.absoluteString, "https://other.example.com/video.m3u8?token=xyz") + } +} From 4d100ffa83e5c1a8be1c1f79f4c51ea72ed781c8 Mon Sep 17 00:00:00 2001 From: Jakub Olejnik Date: Thu, 5 Nov 2026 00:58:51 +0100 Subject: [PATCH 3/3] Add changelog entry for relative playlist URIs with a query string --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19ced800..c7b9e6df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - SideloadedSubtitle - Fixed an issue where subtitles failed to load after the app returned from the background, because the system had closed the connector's local server. - Fixed an issue where the connector's local server kept running after its source was replaced or the player was destroyed. + - Fixed an issue where variant playlists failed to load when the master playlist listed them as relative URIs with a query string, because the query string was percent-encoded into the path. ## [11.0.6] - 2026-09-14