Skip to content

Check to prevent panic #26

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/tidwall/geojson
go 1.15

require (
github.com/stretchr/testify v1.8.4
github.com/tidwall/gjson v1.12.1
github.com/tidwall/lotsa v1.0.2
github.com/tidwall/pretty v1.2.0
Expand Down
17 changes: 17 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
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/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.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tidwall/cities v0.1.0 h1:CVNkmMf7NEC9Bvokf5GoSsArHCKRMTgLuubRTHnH0mE=
github.com/tidwall/cities v0.1.0/go.mod h1:lV/HDp2gCcRcHJWqgt6Di54GiDrTZwh1aG2ZUPNbqa4=
github.com/tidwall/geoindex v1.4.4 h1:hdwzy5qNtK75i7nus59Ibr+SwcH4F2v65bw4txrLJ9M=
Expand All @@ -14,3 +26,8 @@ github.com/tidwall/rtree v1.3.1 h1:xu3vJPKJrmGce7YJcFUCoqLrp9DTUEJBnVgdPSXHgHs=
github.com/tidwall/rtree v1.3.1/go.mod h1:S+JSsqPTI8LfWA4xHBo5eXzie8WJLVFeppAutSegl6M=
github.com/tidwall/sjson v1.2.4 h1:cuiLzLnaMeBhRmEv00Lpk3tkYrcxpmbU81tAY4Dw0tc=
github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
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=
5 changes: 4 additions & 1 deletion object.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ func appendJSONPoint(dst []byte, point geometry.Point, ex *extra, idx int) []byt
dims := int(ex.dims)
for i := 0; i < dims; i++ {
dst = append(dst, ',')
dst = appendJSONFloat(dst, ex.values[idx*dims+i])
k := idx*dims + i
if k < len(ex.values) {
dst = appendJSONFloat(dst, ex.values[k])
}
}
}
dst = append(dst, ']')
Expand Down
3 changes: 2 additions & 1 deletion object_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package geojson

import (
"encoding/json"
"errors"
"fmt"
"math"
"math/rand"
Expand Down Expand Up @@ -77,7 +78,7 @@ func expectJSONOpts(t testing.TB, data string, expect interface{}, opts *ParseOp
exstr = data
}
obj, err := Parse(data, opts)
if err != exerr {
if !errors.Is(err, exerr) {
if t == nil {
panic(fmt.Sprintf("expected '%v', got '%v'", exerr, err))
} else {
Expand Down
11 changes: 11 additions & 0 deletions polygon_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package geojson

import (
"github.com/stretchr/testify/assert"
"testing"
)

Expand Down Expand Up @@ -76,6 +77,16 @@ func TestEmptyPolygon(t *testing.T) {
expect(t, p.JSON() == `{"type":"Polygon","coordinates":[]}`)
}

func TestPanic(t *testing.T) {
p, err := Parse("{\"type\":\"Polygon\",\"coordinates\":[[[0,0],[10,0],[0,10],[0,0]],[[0,0,0],[0,10,0],[10,0,0],[0,0,0]]]}", nil)
if err != nil {
t.Fatal(err)
}
s := p.String()
e := "{\"type\":\"Polygon\",\"coordinates\":[[[0,0],[10,0],[0,10],[0,0]],[[0,0,0],[0,10,0],[10,0,0],[0,0,0]]]}"
assert.Equal(t, e, s)
}

// https://github.com/tidwall/tile38/issues/664
func TestIssue664(t *testing.T) {
// original geojson from issue
Expand Down