gf icon indicating copy to clipboard operation
gf copied to clipboard

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

Open yimuysl001 opened this issue 1 year ago • 4 comments

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": "[email protected]",
			"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>[email protected]</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 avatar Jul 30 '24 01:07 yimuysl001

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

oldme-git avatar Aug 09 '24 03:08 oldme-git

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

Issues-translate-bot avatar Aug 09 '24 03:08 Issues-translate-bot

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

oldme-git avatar Aug 09 '24 03:08 oldme-git

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

Issues-translate-bot avatar Aug 09 '24 03:08 Issues-translate-bot