mirror of
https://github.com/openwrt/luci.git
synced 2026-10-13 22:17:44 +04:00
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>