Skip to content

๐Ÿ› [Bug]: ctx.Bind().JSON hangs when binding JSON containing multi-codepoint characters (e.g., certain emojis)ย #3337

Closed
@mohammadghasemi-com

Description

@mohammadghasemi-com

Bug Description

I'm encountering an issue with the ctx.Bind().JSON method in Fiber when binding JSON payloads that include specific multi-codepoint characters. When these characters are present in the request body, the binding process silently haltsโ€”no error is returned, and the request does not continue.

Steps to Reproduce:

Create a simple Fiber endpoint that uses ctx.Bind().JSON to bind incoming JSON to a struct.
Send a JSON payload where one of the fields contains characters such as:

"๐Ÿ‘โ€๐Ÿ—จ๐Ÿ’€๐Ÿฑโ€๐Ÿ‘ค๐Ÿฑโ€๐Ÿ’ป"

"๏ผ‘๏ผ’๏ผ“๏ผ”๏ผ•"

strings.Repeat("ุจA๐Ÿ˜Š", 85) + "A" (or similar cases with complex emoji sequences)

Observe that the binding process does not complete and no error is logged.
Expected Behavior:
The JSON payload should be successfully bound to the struct even when it contains multi-codepoint characters, such as combined emojis or full-width characters.

Actual Behavior:
When the payload includes these characters, ctx.Bind().JSON does not proceedโ€”it does not return an error nor does it complete the request processing, causing the request to hang.

Additional Information:

I have confirmed that the issue is not related to any custom middleware or third-party packages, as the problem persists even when binding to a raw struct without additional tags.
This issue is reproducible with the provided examples.
It seems related to how Fiber processes or decodes certain Unicode sequences during JSON binding.
Any assistance or insights into this problem would be greatly appreciated. Thank you!

How to Reproduce

1-Create a minimal Fiber server endpoint:
Set up an endpoint that binds the incoming JSON to a simple struct (e.g., one with a Name field) using ctx.Bind().JSON.

2-Prepare the JSON payload:
Construct a JSON payload that includes problematic characters. For example:

For the Name field, use: "๐Ÿ‘โ€๐Ÿ—จ๐Ÿ’€๐Ÿฑโ€๐Ÿ‘ค๐Ÿฑโ€๐Ÿ’ป"
Alternatively, try other examples like "๏ผ‘๏ผ’๏ผ“๏ผ”๏ผ•" or a string generated by strings.Repeat("ุจA๐Ÿ˜Š", 85) + "A".

3-Send the request:
Use an HTTP client (e.g., Postman or curl) to send the JSON payload to your endpoint.

4-Observe the behavior:
Notice that the binding process hangs silentlyโ€”no error is returned and the request does not complete.

In the expected outcome, the JSON should be successfully bound to the struct regardless of the characters used, and the request should complete normally.

Expected Behavior

When a JSON payload containing multi-codepoint characters is sent, ctx.Bind().JSON should successfully parse and bind the data to the target struct without hanging. For example, fields with values like "๐Ÿ‘โ€๐Ÿ—จ๐Ÿ’€๐Ÿฑโ€๐Ÿ‘ค๐Ÿฑโ€๐Ÿ’ป", "๏ผ‘๏ผ’๏ผ“๏ผ”๏ผ•", or strings generated by strings.Repeat("ุจA๐Ÿ˜Š", 85) + "A" should be processed normally, and the request should complete with either a proper response or continue with subsequent middleware/handlers as expected.

Fiber Version

v3.0.0-beta.3

Code Snippet (optional)

package main

import (
	"log"

	"github.com/gofiber/fiber/v2"
)

type RequestData struct {
	Name string `json:"name"`
}

func main() {
	app := fiber.New()

	app.Post("/test", func(c *fiber.Ctx) error {
		var reqData RequestData

		// Attempt to bind JSON to the struct
		err := c.Bind().JSON(&reqData)
		if err != nil {
			log.Printf("Binding error: %v", err)
			return c.Status(fiber.StatusBadRequest).SendString("Bad Request")
		}

		// If binding is successful, return the bound data as JSON
		return c.JSON(reqData)
	})

	log.Fatal(app.Listen(":3000"))
}

type Users struct {
	Name      string  `json:"name"``
}

Checklist:

  • I agree to follow Fiber's Code of Conduct.
  • I have checked for existing issues that describe my problem prior to opening this one.
  • I understand that improperly formatted bug reports may be closed without explanation.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions