Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
3 tasks done
mohammadghasemi-com opened this issue Mar 3, 2025 · 4 comments

Comments

@mohammadghasemi-com
Copy link

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:

"👁‍🗨💀🐱‍👤🐱‍💻"

"12345"

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 "12345" 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 "👁‍🗨💀🐱‍👤🐱‍💻", "12345", 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.
Copy link

welcome bot commented Mar 3, 2025

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@ReneWerner87 ReneWerner87 added the v3 label Mar 3, 2025
@ReneWerner87 ReneWerner87 added this to v3 Mar 3, 2025
@ReneWerner87 ReneWerner87 added this to the v3 milestone Mar 3, 2025
@ReneWerner87
Copy link
Member

We will check this
Thank you for the report

@devhaozi
Copy link
Contributor

devhaozi commented Mar 3, 2025

I can't reproduce this. (I tested this with fiber v3, but I noticed that your example incorrectly uses fiber v2)

Image

@mohammadghasemi-com
Copy link
Author

Issue resolved. The problem was on my end; the framework did not have any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

No branches or pull requests

3 participants