Skip to content

bugfix: tjs.format breaks with a non-string first arg#741

Merged
saghul merged 2 commits intosaghul:masterfrom
ldeninski:bugfix/console-log-and-tjs-format-broken-with-non-string-first-arg
Jan 23, 2026
Merged

bugfix: tjs.format breaks with a non-string first arg#741
saghul merged 2 commits intosaghul:masterfrom
ldeninski:bugfix/console-log-and-tjs-format-broken-with-non-string-first-arg

Conversation

@ldeninski
Copy link
Copy Markdown
Contributor

This PR tl;dr;

  • fixeds a bug in util.format polyfill that causes the output to break if the first arg is not a string
  • optimizes the format function a bit
  • adds test cases for the problematic behavior and the happy case

The bug is in browserify/node-util polyfill (including the most recent version). Here's a log from an exaggerated test case:

dr0p@dr0p-rog:~$ tjs
Welcome to txiki.js - Type ".help" for help
> tjs.engine.versions
{
  quickjs: '0.10.1',
  tjs: '24.12.0',
  uv: '1.50.0',
  curl: 'libcurl/8.5.0 OpenSSL/3.0.13 zlib/1.3 brotli/1.1.0 zstd/1.5.5 libidn2/2.3.7 li...',
  wasm3: '0.5.1',
  sqlite3: '3.46.0',
  mimalloc: 212
}
> console.log("col1\t\tcol2", 42); // happy case
col1		col2 42
undefined
> console.log(1, "col1\t\tcol2", 42); // broken case
1 'col1\t\tcol2' 42
undefined

and after the fix:

✔ ~/_DEV/_KOBO/txiki.js [bugfix/console-log-and-tjs-format-broken-with-non-string-first-arg|✔]
12:58 $ ./build/tjs
Welcome to txiki.js - Type ".help" for help
> tjs.engine.versions
{
  quickjs: '0.10.1',
  tjs: '24.12.0',
  uv: '1.50.0',
  curl: 'libcurl/8.5.0 OpenSSL/3.0.13 zlib/1.3 brotli/1.1.0 zstd/1.5.5 libidn2/2.3.7 li...',
  wasm3: '0.5.1',
  sqlite3: '3.46.0',
  mimalloc: 212
}
> console.log("col1\t\tcol2", 42); // happy case
col1		col2 42
undefined
> console.log(1, "col1\t\tcol2", 42); // broken case
1 col1		col2 42
undefined
> 

Here's for reference nodejs's output of the same case:

✔ ~/_DEV/_KOBO/txiki.js [bugfix/console-log-and-tjs-format-broken-with-non-string-first-arg|✔] 
13:00 $ node
Welcome to Node.js v24.13.0.
Type ".help" for more information.
> process.version
'v24.13.0'
> console.log("col1\t\tcol2", 42); // happy case
col1		col2 42
undefined
> console.log(1, "col1\t\tcol2", 42); // broken case
1 col1		col2 42
undefined
> 

… if the first arg is not a string

- optimized the format function a bit
- added test cases for problematic behavior and the happy case
@saghul saghul merged commit 742660f into saghul:master Jan 23, 2026
19 checks passed
@saghul
Copy link
Copy Markdown
Owner

saghul commented Jan 23, 2026

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants