Files
luci/modules
Cristian Papa 8deadcf01d luci-base: don't crash in String.format() on an undefined argument
A `%<n>m` conversion stores its divisor in the min-length slot, but when
the argument was undefined the `if (param !== undefined)` block was
skipped, so the divisor was never cleared while `subst` stayed undefined
and the trailing `subst.toString()` in the padding loop threw.

Use an empty substitution for an undefined argument and preserve the
parsed field width, so values such as `'%10s'.format(undefined)` render
as padding plus an empty string (ten spaces). `%m` stays special: it
reuses the min-length slot as the metric divisor, not a field width, so
clear it for undefined `%m` conversions just like the defined-argument
path does, to avoid padding the empty value out to ~1024 characters.

Also move the pad initialization ahead of the `param !== undefined` check
so the common padding block has a valid pad character for undefined
arguments too.

As a side effect a plain `%s`/`%d` on an undefined argument now yields an
empty string instead of the literal "undefined".

Signed-off-by: Cristian Papa <pcristian292@gmail.com>
2026-07-20 21:39:40 +02:00
..