diff --git a/src/modules/util.c b/src/modules/util.c index 507ba69..f06c71a 100644 --- a/src/modules/util.c +++ b/src/modules/util.c @@ -181,7 +181,9 @@ static ant_value_t util_format_impl(ant_t *js, ant_value_t *args, int nargs, int util_sb_append_json(js, &sb, v); } else if (spec == 'o' || spec == 'O') { util_sb_append_jsval(js, &sb, v); - } else if (spec == 'c') // style placeholder: consume arg, emit nothing + } else if (spec == 'c') { + // style placeholder: consume arg, emit nothing. + } i++; } diff --git a/tests/repro_obug_format.mjs b/tests/repro_obug_format.mjs new file mode 100644 index 0000000..8250def --- /dev/null +++ b/tests/repro_obug_format.mjs @@ -0,0 +1,32 @@ +import { formatWithOptions } from 'node:util'; +import process from 'node:process'; + +function humanize(value) { + if (value >= 1000) return `${(value / 1000).toFixed(1)}s`; + return `${value}ms`; +} + +function writeDebugLine(namespace, args, diff) { + const prefix = ` \u001B[32;1m${namespace} \u001B[0m`; + args[0] = prefix + args[0].split('\n').join(`\n${prefix}`); + args.push(`\u001B[32m+${humanize(diff)}\u001B[0m`); + return formatWithOptions({}, ...args); +} + +const raw = formatWithOptions({}, '%s %s : %s', 'fn', '/', '/foo.png'); +const debugLine = writeDebugLine('repro:test', ['%s %s : %s', 'fn', '/', '/foo.png'], 0); + +console.log('raw:'); +console.log(raw); +console.log('debug:'); +console.log(debugLine); + +if (raw !== 'fn / : /foo.png') { + throw new Error(`util.formatWithOptions mismatch: ${JSON.stringify(raw)}`); +} + +if (!debugLine.includes('fn / : /foo.png')) { + throw new Error(`obug-style line mismatch: ${JSON.stringify(debugLine)}`); +} + +process.exit(0);