Skip to content

Fix breaking change to behaviour in sprintf #70824

@nerrad

Description

@nerrad

Description

#70434 switched the underlying library used for sprintf to use @tannin/sprintf instead of sprintf-js. While the stronger typing is a good improvement, the change is breaking for any usage of sprintf in the wild which passes in undefined as the format string (example).

To be explicit (quoting @aduth from this comment):

  • sprintf('Hello, %(name)s', { name: undefined }) ➡️ 'Hello, '
  • sprintf('Hello, %(name)s', undefined) ➡️ 'Hello, '
  • sprintf(undefined); ➡️ Uncaught TypeError: Cannot read properties of undefined (reading 'replace')

Might not be an overly common case, given it would likely only surface when a variable is passed into sprintf for the format string (and that variable might be undefined).

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Metadata

Metadata

Assignees

No one assigned

    Labels

    [Package] i18n/packages/i18n[Type] BugAn existing feature does not function as intended

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions