cloudwego / hertz

Go HTTP framework with high-performance and strong-extensibility for building micro-services.
https://www.cloudwego.io
Apache License 2.0
5.04k stars 491 forks source link

ctx.JSON默认开启HTML转义吗? #1142

Closed ljkk closed 1 month ago

ljkk commented 1 month ago
package main

import (
    "context"

    "github.com/cloudwego/hertz/pkg/app"
    "github.com/cloudwego/hertz/pkg/app/server"
    "github.com/cloudwego/hertz/pkg/common/utils"
    "github.com/cloudwego/hertz/pkg/protocol/consts"
)

func main() {
    h := server.Default(server.WithExitWaitTime(0))

    h.GET("/ping", func(c context.Context, ctx *app.RequestContext) {
            ctx.JSON(consts.StatusOK, utils.H{"message": "<>pong<>"})
    })

    h.Spin()

}

// curl http://127.0.0.1:8888/ping,期望返回:{"message":"<>pong<>"},实际返回:{"message":"\u003c\u003epong\u003c\u003e"}

rogerogers commented 1 month ago

https://www.cloudwego.io/docs/hertz/tutorials/basic-feature/render/#purejson

github-actions[bot] commented 1 month ago

This issue has been marked as invalid question, please give more information by following the issue template. The issue will be closed in 1 days if no further activity occurs.