diff --git a/go.mod b/go.mod index 0c470a7..2c17167 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,4 @@ module git.merith.xyz/packages/jar-dedupe go 1.20 -require ( - github.com/pelletier/go-toml v1.9.5 // indirect - github.com/pelletier/go-toml/v2 v2.0.7 // indirect -) +require github.com/pelletier/go-toml/v2 v2.0.7 diff --git a/go.sum b/go.sum index cc985f1..81ed8bd 100644 --- a/go.sum +++ b/go.sum @@ -1,16 +1,18 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= -github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= github.com/pelletier/go-toml/v2 v2.0.7 h1:muncTPStnKRos5dpVKULv2FVd4bMOhNePj9CjgDb8Us= github.com/pelletier/go-toml/v2 v2.0.7/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/main.go b/main.go index 4c88406..540d371 100644 --- a/main.go +++ b/main.go @@ -2,11 +2,13 @@ package main import ( "archive/zip" + "bytes" "encoding/json" "io/ioutil" "log" "os" "regexp" + "strings" "github.com/pelletier/go-toml/v2" ) @@ -98,10 +100,19 @@ func readMod(filename string) (string, string, string) { defer zipReader.Close() for _, file := range zipReader.File { contents, _ := file.Open() + + // * Clean stray \n characters from the json + var buf bytes.Buffer + _, err := buf.ReadFrom(contents) + if err != nil { + log.Fatalln("[READ FROM]", err) + } + cleanedContents := strings.ReplaceAll(buf.String(), "\n", "") + // * End Clean + if file.Name == "fabric.mod.json" { loader = "fabric" - // add to fabric list - fabricJsonErr := json.NewDecoder(contents).Decode(&fabricJson) + fabricJsonErr := json.Unmarshal([]byte(cleanedContents), &fabricJson) if fabricJsonErr != nil { log.Println("[DECODE ERROR]", filename) log.Fatalln("[DECODE FABRIC MOD]", fabricJsonErr) @@ -110,7 +121,7 @@ func readMod(filename string) (string, string, string) { } if file.Name == "quilt.mod.json" { loader = "quilt" - quiltJsonErr := json.NewDecoder(contents).Decode(&quiltJson) + quiltJsonErr := json.Unmarshal([]byte(cleanedContents), &quiltJson) if quiltJsonErr != nil { log.Println(filename) log.Println("[DECODE ERROR]", filename) @@ -120,7 +131,6 @@ func readMod(filename string) (string, string, string) { } if file.Name == "META-INF/mods.toml" { loader = "forge" - //add to forge list forgeTomlErr := toml.NewDecoder(contents).Decode(&forgeMod) if forgeTomlErr != nil { log.Println("[DECODE ERROR]", filename)