Files
iptvnator/apps/electron-backend/src/app/util/mpv-string-list.util.ts
T
4grayandClaude Fable 5 9bb1811984 fix(playback): escape commas in mpv header fields on the TS paths (#1323)
* fix(playback): escape commas in mpv header fields on the TS paths

PR #1321 fixed the comma truncation of --http-header-fields inside the
native embedded-mpv addon, but the same OPT_STRINGLIST parsing bites
three TypeScript call sites that join header fields with ',':

- external MPV CLI launch (--http-header-fields=...)
- external MPV instance reuse (set_property http-header-fields)
- embedded MPV frame-copy loadfile options (opt.http-header-fields);
  the helper's %len% quoting protects only the option-list level, mpv
  still stringlist-parses the value afterwards

The Stalker MAG user agent contains "(KHTML, like Gecko)", so strict
portals received a truncated X-User-Agent and rejected live streams
with HTTP 400 (#910). Escape backslashes and commas per field with the
same scheme as the native fix, via a shared util.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* test(playback): cover the reused-instance IPC header escaping

Review follow-up (Greptile on #1323): the regression coverage only
exercised the CLI spawn path. Capture the JSON IPC traffic of a second,
reused mpv launch and assert the escaped MAG user agent survives the
set_property http-header-fields transport, so later serialization
changes cannot silently reintroduce truncated headers. net is mocked
with a passthrough default because the VLC specs bind a real ephemeral
port via createServer.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-08-01 16:19:38 +02:00

17 lines
796 B
TypeScript

/**
* mpv's `http-header-fields` option is a comma-separated list
* (OPT_STRINGLIST). Header values that themselves contain commas — e.g. the
* Stalker MAG250 user agent "...(KHTML, like Gecko) MAG250" — must be escaped
* or mpv splits them into bogus fields and the server rejects the request
* (HTTP 400). mpv strips the backslash and keeps the comma inside the value.
* Mirrors the escaping of the native embedded-mpv addon (PR #1321).
*/
export function escapeMpvStringListValue(value: string): string {
return value.replace(/\\/g, '\\\\').replace(/,/g, '\\,');
}
/** Join `Name: value` header fields into one mpv stringlist option value. */
export function joinMpvHeaderFields(fields: readonly string[]): string {
return fields.map(escapeMpvStringListValue).join(',');
}