M3U parser: names with commas get truncated, BOM breaks the first entry, no format validation #10
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
Three separate defects in
M3uParser:1. Commas in display names truncate the name. The name is taken with
substringAfterLast(','), which finds the last comma in the line rather than the field separator after the duration.#EXTINF:-1,Comedy Central, HDyieldsHD— everything before the last comma is silently lost. Any channel named "News, Sport" or similar is affected.2. A UTF-8 BOM corrupts the first entry.
trim()strips whitespace, and U+FEFF is not whitespace; the reader does not strip it either. The first line becomes"#EXTM3U", sostartsWith("#")is false and the header falls through into the "bare URL" branch, injecting a junk channel named#EXTM3U. If the BOM precedes an#EXTINFinstead, that channel's metadata is swallowed and its URL becomes its own name.3. Any text parses as a "valid" playlist. There is no
#EXTM3Ucheck and no structural validation — every non-#line becomes a channel, and the caller only asserts the result is non-empty. Point the app at a 404 HTML page and you get six channels named<!DOCTYPE html>,<html>,<body>… cached to disk as the real channel list, with no error shown. Same for an HLS media playlist, where every segment URL becomes a "channel".Failure scenario
Someone pastes a slightly wrong URL under "Erweitert". Instead of "das sieht nicht nach einer Senderliste aus", the app cheerfully replaces the working list with HTML fragments and persists them.
Suggested fix
#EXTINFline at the first comma after the duration field, not the last comma in the line#EXTM3Uheader (or at least one#EXTINF) and reject the payload otherwise, with a plain-language messageFound by multi-agent code review; the parser is unchanged from the reviewed version.
Fixed in
dd612fc, shipped in v0.9.0 — with unit tests, since the comma logic is easy to get subtly wrong.#EXTINF:-1 group-title="News, Sport",Das Erste HDyieldsDas Erste HDand the groupNews, Sport. Commas inside quoted attributes are ignored by the splitter.#EXTM3Uis recognised instead of becoming a junk channel.looksLikePlaylist()scans the first 50 lines for#EXTM3Uor#EXTINF; without either,parse()throwsNotAPlaylistExceptionand the caller surfaces the existing playlist error instead of caching HTML fragments as channels.#EXTGRPnow inherits that group instead of dropping it.Tests live in
tests/unit/M3uParserTest.kt(Gradle points its unit-test source set there, reports go totests/runs/, per the repo's test layout). 8 cases, all green: