Skip to content

fix(splat): stop char-spreading leftover primitive metas into info - #362

Open
abhu85 wants to merge 1 commit into
winstonjs:masterfrom
abhu85:fix/109-splat-string-char-spread
Open

fix(splat): stop char-spreading leftover primitive metas into info#362
abhu85 wants to merge 1 commit into
winstonjs:masterfrom
abhu85:fix/109-splat-string-char-spread

Conversation

@abhu85

@abhu85 abhu85 commented Jul 20, 2026

Copy link
Copy Markdown

Summary

format.splat() merges any splat arguments beyond the interpolation tokens into info via Object.assign. When a leftover argument is a primitive string, Object.assign spreads its characters into index-keyed properties.

Fixes #109

Problem

logger.error('one %s', 'two', 'three');
// { "0":"t","1":"h","2":"r","3":"e","4":"e", level:"error", message:"one two" }

After %s consumes 'two', the leftover 'three' is a string, and Object.assign(info, 'three') treats it like an object with enumerable index keys, polluting info with {0:'t',1:'h',...}.

Solution

In Splatter._splat, only merge a leftover meta into info when it is a non-null object (typeof meta === 'object' && meta !== null). Object and array metas are unchanged; primitive leftovers are no longer char-spread.

Test Plan

  • Added a regression test asserting input 'one %s' + [SPLAT] = ['two','three'] yields message === 'one two' with no 0..4 index properties on info.
  • Fails before the fix (info[0] === 't'), passes after.
  • Full suite: 170 passing, 0 failing. Lint: 0 errors.

Compatibility

Object/array metas (the documented use case) behave exactly as before — covered by existing passing tests. Only the spurious character-index pollution from primitive leftovers is removed. The separate no-token code path is intentionally left untouched to avoid contradicting its existing test.

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.

splat() spreads individual characters of unreferenced string into result

1 participant