Skip to main content

Function: escapeSubparam()

function escapeSubparam(value: string): string;

Defined in: packages/player/src/subparam.ts:69

Escape one sub-option key or value the way mpv itself does.

Parameters

ParameterTypeDescription
valuestringRaw key or value.

Returns

string

value unchanged when every character is in NAMECH, otherwise mpv's fixed-length form %<utf8 bytes>%<value>.

Remarks

The fixed-length form is chosen over "…"/[…] because it is the only one with no forbidden characters at all: the parser reads exactly the number of bytes it is told and stops, so a value containing ,, :, ", [, ], \ or a leading % survives verbatim. read_subparam parses the count with bstrtoll(p, &p, 0) — base zero, i.e. a leading 0 would be read as octal — which is safe here because a length is only ever written without leading zeros.