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

encoding/gjson: converting error from json to xml when there're special chars #3716

Closed
yimuysl001 opened this issue Jul 30, 2024 · 4 comments · Fixed by #3740
Closed

encoding/gjson: converting error from json to xml when there're special chars #3716

yimuysl001 opened this issue Jul 30, 2024 · 4 comments · Fixed by #3740
Assignees
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.

Comments

@yimuysl001
Copy link

Go version

go1.20.14 windows/amd64

GoFrame version

2.7.1

Can this bug be reproduced with the latest release?

Option Yes

What did you do?

json转xml时特殊字符未能转换,导致xml格式不正确,也不能正确还原回json

What did you see happen?

package main

import (
	"fmt"
	"github.com/gogf/gf/v2/encoding/gjson"
)

func main() {
	// 假设的map数据
	data := map[string]interface{}{
		"Person": map[string]interface{}{
			"Name":  "<>&'\"AAA",
			"Email": "john.doe@example.com",
			"Bio":   "I am a software developer & I love coding.",
		},
	}

	indentString, err2 := gjson.New(data).ToXmlString("root")
        // 特殊字符 <> & ' " 未能正常转义 ,xml格式解析不正确
	fmt.Println(indentString) // <root><Person><Bio>I am a software developer & I love coding.</Bio><Email>john.doe@example.com</Email><Name><>&'"AAA</Name></Person></root>
	fmt.Println(err2)

	m := gjson.New(indentString).Map()
	fmt.Println(m) // map[]

}

What did you expect to see?

希望在转xml时,特殊字符能一并转化

@yimuysl001 yimuysl001 added the bug It is confirmed a bug, but don't worry, we'll handle it. label Jul 30, 2024
@oldme-git oldme-git self-assigned this Aug 9, 2024
@oldme-git
Copy link
Member

XML 依赖其他三方库,等待第三方库 PR 通过后升级依赖版本修复此 BUG。或者更换第三方库

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


XML depends on other third-party libraries. Wait for the PR of the third-party library to be passed and then upgrade the dependent version to fix this bug. Or replace the third-party library

@oldme-git
Copy link
Member

信息补充:不再使用第三方库处理 XML,切换成标准库 encoding/xml

@Issues-translate-bot
Copy link

Bot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


Additional information: No longer use third-party libraries to process XML, switch to the standard library encoding/xml

@gqcn gqcn changed the title encoding/gjson: json转xml时特殊字符未能转换,导致xml格式不正确,也不能正确还原回json encoding/gjson: converting error from json to xml when there're special chars Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug It is confirmed a bug, but don't worry, we'll handle it.
Projects
None yet
3 participants