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 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 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") + } +}