mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-15 15:48:05 +00:00
fix(hls): parse M3U8 attributes respecting quoted strings
The previous implementation split on commas without respecting quoted values, causing subtitles with commas in names (e.g., "English, Forced") or URIs with special characters to be incorrectly parsed. Uses regex to properly match key=value pairs where values can be either quoted (containing any characters except quotes) or unquoted (no commas).
This commit is contained in:
@@ -44,12 +44,14 @@ export async function parseM3U8ForSubtitles(
|
||||
|
||||
function parseAttributes(line: string): { [key: string]: string } {
|
||||
const attributes: { [key: string]: string } = {};
|
||||
const parts = line.split(",");
|
||||
parts.forEach((part) => {
|
||||
const [key, value] = part.split("=");
|
||||
if (key && value) {
|
||||
attributes[key.trim()] = value.replace(/"/g, "").trim();
|
||||
}
|
||||
});
|
||||
const regex = /([A-Z-]+)=(?:"([^"]*)"|([^,]*))/g;
|
||||
let match: RegExpExecArray | null;
|
||||
|
||||
while ((match = regex.exec(line)) !== null) {
|
||||
const key = match[1];
|
||||
const value = match[2] ?? match[3]; // quoted or unquoted
|
||||
attributes[key] = value;
|
||||
}
|
||||
|
||||
return attributes;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user