go-xmlfmt / xmlfmt Goto Github PK
View Code? Open in Web Editor NEWGo XML Formatter (Beautifier)
License: MIT License
Go XML Formatter (Beautifier)
License: MIT License
I have an xml
<book>
<author>Fred</author>
<!--
<price>20</price><currency>USD</currency>
-->
<isbn>23456</isbn>
</book>
It fails to parse
panic: strings: negative Repeat count
When I tried to run the below code, panic is occured
package main
import "github.com/go-xmlfmt/xmlfmt"
func main() {
msg := `<!-- 무조건 착신전환 조회 -->
<?xml version="1.0" encoding="utf-8"?>
<message name="DIS_USER_SSVC" tid="1591918441">
<!-- 결과 코드 : 0(성공) / 그 외(실패) -->
<Result>0</Result>
<parameter>
<SsvcList>
<!-- 가입/사용 여부 : 3(가입+사용 중) / 2(가입+미사용) -->
<CFU>2</CFU>
<!-- 착신 번호(CFU 가 3인 경우 사용) -->
<!-- <DATA>0261216281</DATA> -->
</SsvcList>
</parameter>
</message>`
xmlfmt.FormatXML(string(msg), "", "\t")
}
the error trace is
panic: strings: negative Repeat count
goroutine 1 [running]:
strings.Repeat({0x102cb4c14, 0x1}, 0xffffffffffffffff)
/usr/local/go/src/strings/strings.go:529 +0x41c
github.com/go-xmlfmt/xmlfmt.replaceTag.func1({0x1400011e195, 0xa})
/Users/hanyoungtak/Documents/go/pkg/mod/github.com/go-xmlfmt/[email protected]/xmlfmt.go:48 +0x24c
regexp.(*Regexp).ReplaceAllStringFunc.func1({0x1400011c300, 0x1cd, 0x300}, {0x14000016240, 0x2, 0x2})
/usr/local/go/src/regexp/regexp.go:596 +0x78
regexp.(*Regexp).replaceAll(0x1400007c0a0, {0x0, 0x0, 0x0}, {0x1400011e000, 0x19f}, 0x2, 0x14000105e98)
/usr/local/go/src/regexp/regexp.go:634 +0x314
regexp.(*Regexp).ReplaceAllStringFunc(0x1400007c0a0, {0x1400011e000, 0x19f}, 0x14000068210)
/usr/local/go/src/regexp/regexp.go:595 +0x74
github.com/go-xmlfmt/xmlfmt.FormatXML({0x102cbacae, 0x1cf}, {0x0, 0x0}, {0x102cb4c14, 0x1})
/Users/hanyoungtak/Documents/go/pkg/mod/github.com/go-xmlfmt/[email protected]/xmlfmt.go:25 +0xc4
main.main()
/Users/hanyoungtak/Documents/go/src/xml-test/main.go:20 +0x4c
Ciao,
I try to format this string but receive a panic.
"<book><author>Fred</author><text><![CDATA[<message> Welcome to xmlfmt </message>]]></text><isbn>23456</isbn></book>"
Just as the title said.
package main
import (
"fmt"
"io/ioutil"
"github.com/go-xmlfmt/xmlfmt"
)
func main() {
xmlfile := "/Users/bruce/Downloads/example.fcpxml"
b, _ := ioutil.ReadFile(xmlfile)
xml := xmlfmt.FormatXML(string(b), "", " ")
fmt.Println(xml)
}
xmlfmt.FormatXML()
auto adds a \n
before </text-style>
Here is the contents of example.fcpxml
, there's no \n
before </text-style>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE fcpxml>
<fcpxml version="1.10">
<resources>
<format id="r1" name="FFVideoFormat_1920x1080_30p" frameDuration="100/3000s" width="1920" height="1080" colorSpace="1-1-1 (Rec. 709)"/>
<effect id="r2" name="Basic Title" uid=".../Titles.localized/Bumper:Opener.localized/Basic Title.localized/Basic Title.moti"/>
</resources>
<library location="file:///Users/bruce/Movies/Untitled.fcpbundle/">
<event name="Titles Event" uid="0F964C4C-82A5-40FC-873A-115B5F5F134D">
<project name="202202062300" uid="6CDE04AC-E1FD-41FE-BFBE-34332D019BB4" modDate="2022-02-07 00:14:53 +0800">
<sequence format="r1" duration="13000/3000s" tcStart="0s" tcFormat="NDF" renderFormat="FFRenderFormatProRes422HQ" audioLayout="stereo" audioRate="48k">
<spine>
<gap name="Gap" offset="0s" start="3600s" duration="13000/3000s">
<title name="Default Title - Basic Title" lane="1" offset="10800700/3000s" ref="r2" duration="3000/3000s" start="3600s">
<param name="Flatten" key="9999/999166631/999166633/2/351" value="1"/>
<param name="Alignment" key="9999/999166631/999166633/2/354/999169573/401" value="1 (Center)"/>
<param name="Position" key="9999/999166631/999166633/1/100/101" value="0 20.631"/>
<text>
<text-style ref="ts1">Default Title</text-style>
</text>
<text-style-def id="ts1">
<text-style font="DFP King Gothic GB Medium" fontSize="56" fontFace="Regular" fontColor="1 1 1 1" alignment="center"/>
</text-style-def>
</title>
<title name="Default Title - Basic Title" lane="1" offset="10805200/3000s" ref="r2" duration="3100/3000s" start="3600s">
<param name="Flatten" key="9999/999166631/999166633/2/351" value="1"/>
<param name="Alignment" key="9999/999166631/999166633/2/354/999169573/401" value="1 (Center)"/>
<param name="Position" key="9999/999166631/999166633/1/100/101" value="0 20.631"/>
<text>
<text-style ref="ts2">Default Title</text-style>
</text>
<text-style-def id="ts2">
<text-style font="DFP King Gothic GB Medium" fontSize="56" fontFace="Regular" fontColor="1 1 1 1" alignment="center"/>
</text-style-def>
</title>
<title name="Default Title - Basic Title" lane="1" offset="10810200/3000s" ref="r2" duration="2800/3000s" start="3600s">
<param name="Flatten" key="9999/999166631/999166633/2/351" value="1"/>
<param name="Alignment" key="9999/999166631/999166633/2/354/999169573/401" value="1 (Center)"/>
<param name="Position" key="9999/999166631/999166633/1/100/101" value="0 20.631"/>
<text>
<text-style ref="ts3">Default Title</text-style>
</text>
<text-style-def id="ts3">
<text-style font="DFP King Gothic GB Medium" fontSize="56" fontFace="Regular" fontColor="1 1 1 1" alignment="center"/>
</text-style-def>
</title>
</gap>
</spine>
</sequence>
</project>
</event>
<smart-collection name="Favorites" match="all">
<match-ratings value="favorites"/>
</smart-collection>
<smart-collection name="Stills" match="all">
<match-media rule="is" type="stills"/>
</smart-collection>
<smart-collection name="All Videos" match="any">
<match-media rule="is" type="videoOnly"/>
<match-media rule="is" type="videoWithAudio"/>
</smart-collection>
<smart-collection name="Audio Only" match="all">
<match-media rule="is" type="audioOnly"/>
</smart-collection>
<smart-collection name="Project" match="all">
<match-clip rule="is" type="project"/>
</smart-collection>
</library>
</fcpxml>
Hi @AntonioSun, I updated to 7fd73a9 but It still happened...
package main
import "github.com/go-xmlfmt/xmlfmt"
func main() {
msg := `<!-- 무조건 착신전환 조회 -->
<?xml version="1.0" encoding="utf-8"?>
<message name="DIS_USER_SSVC" tid="1591918441">
<!-- 결과 코드 : 0(성공) / 그 외(실패) -->
<Result>0</Result>
<parameter>
<SsvcList>
<!-- 가입/사용 여부 : 3(가입+사용 중) / 2(가입+미사용) -->
<CFU>2</CFU>
<!-- 착신 번호(CFU 가 3인 경우 사용) -->
<!-- <DATA>0261216281</DATA> -->
</SsvcList>
</parameter>
</message>`
xmlfmt.FormatXML(string(msg), "", "\t")
}
trace is
panic: strings: negative Repeat count
goroutine 1 [running]:
strings.Repeat({0x104e14937, 0x1}, 0xffffffffffffffff)
/usr/local/go/src/strings/strings.go:529 +0x41c
github.com/go-xmlfmt/xmlfmt.replaceTag.func1({0x1400015019f, 0xa})
/Users/hanyoungtak/Documents/go/pkg/mod/github.com/go-xmlfmt/[email protected]/xmlfmt.go:69 +0x24c
regexp.(*Regexp).ReplaceAllStringFunc.func1({0x1400014e300, 0x1d7, 0x300}, {0x140001260c0, 0x2, 0x2})
/usr/local/go/src/regexp/regexp.go:596 +0x78
regexp.(*Regexp).replaceAll(0x14000118140, {0x0, 0x0, 0x0}, {0x14000150000, 0x1a9}, 0x2, 0x1400012fe58)
/usr/local/go/src/regexp/regexp.go:634 +0x314
regexp.(*Regexp).ReplaceAllStringFunc(0x14000118140, {0x14000150000, 0x1a9}, 0x14000106270)
/usr/local/go/src/regexp/regexp.go:595 +0x74
github.com/go-xmlfmt/xmlfmt.FormatXML({0x104e1eb08, 0x1d9}, {0x0, 0x0}, {0x104e14937, 0x1}, {0x0, 0x0, 0x0})
/Users/hanyoungtak/Documents/go/pkg/mod/github.com/go-xmlfmt/[email protected]/xmlfmt.go:38 +0x144
main.main()
/Users/hanyoungtak/Documents/go/src/xml-test/main.go:22 +0x54
exit status 2
the blow line caused the error.
<!-- <DATA>0261216281</DATA> -->
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.