Skip to content

6.1.0: Breaks Fastify error serialization for messages which contain quotes #794

@Senney

Description

@Senney

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

5.6.1

Plugin version

6.1.0

Node.js version

23.11.0

Operating system

macOS

Operating system version (i.e. 20.04, 11.3, 10)

15.6.1

Description

After updating fast-json-stringify to 6.1.0, error messages which contain double-quotes (") are not correctly serialized to JSON when using a custom Validator Compiler which returns a FastifyValidationResult that contains an errors array.

This was introduced in #774 when the error serializer code was switched to use isWellFormed, rather than evaluating against a regular expression. The regular expression which was present before:

/[\u0000-\u001f\u0022\u005c\ud800-\udfff]/

Detected the following characters:

  • Control characters
  • Quotation marks
  • Backslashes

The switch to only use isWellFormed removes the backslash and quotation detection.

Link to code that reproduces the bug

https://github.com/Senney/fastify-fast-json-stringify-bug

Expected Behavior

Validation error messages which contain quotation marks should pass through JSON.stringify as expected, or be escaped through other means.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions