Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f445202cb8 |
+18
-14
@@ -74,39 +74,43 @@ universal_binaries:
|
||||
name_template: jsontoml
|
||||
archives:
|
||||
- id: jsontoml
|
||||
format: tar.xz
|
||||
builds:
|
||||
formats:
|
||||
- tar.xz
|
||||
ids:
|
||||
- jsontoml
|
||||
files:
|
||||
- none*
|
||||
name_template: "{{ .Binary }}_{{.Version}}_{{ .Os }}_{{ .Arch }}"
|
||||
- id: tomljson
|
||||
format: tar.xz
|
||||
builds:
|
||||
formats:
|
||||
- tar.xz
|
||||
ids:
|
||||
- tomljson
|
||||
files:
|
||||
- none*
|
||||
name_template: "{{ .Binary }}_{{.Version}}_{{ .Os }}_{{ .Arch }}"
|
||||
- id: tomll
|
||||
format: tar.xz
|
||||
builds:
|
||||
formats:
|
||||
- tar.xz
|
||||
ids:
|
||||
- tomll
|
||||
files:
|
||||
- none*
|
||||
name_template: "{{ .Binary }}_{{.Version}}_{{ .Os }}_{{ .Arch }}"
|
||||
dockers:
|
||||
dockers_v2:
|
||||
- id: tools
|
||||
goos: linux
|
||||
goarch: amd64
|
||||
ids:
|
||||
- jsontoml
|
||||
- tomljson
|
||||
- tomll
|
||||
image_templates:
|
||||
- "ghcr.io/pelletier/go-toml:latest"
|
||||
- "ghcr.io/pelletier/go-toml:{{ .Tag }}"
|
||||
- "ghcr.io/pelletier/go-toml:v{{ .Major }}"
|
||||
skip_push: false
|
||||
images:
|
||||
- "ghcr.io/pelletier/go-toml"
|
||||
tags:
|
||||
- "latest"
|
||||
- "{{ .Tag }}"
|
||||
- "v{{ .Major }}"
|
||||
platforms:
|
||||
- linux/amd64
|
||||
checksum:
|
||||
name_template: 'sha256sums.txt'
|
||||
snapshot:
|
||||
|
||||
+4
-3
@@ -1,5 +1,6 @@
|
||||
FROM scratch
|
||||
ENV PATH "$PATH:/bin"
|
||||
COPY tomll /bin/tomll
|
||||
COPY tomljson /bin/tomljson
|
||||
COPY jsontoml /bin/jsontoml
|
||||
ARG TARGETPLATFORM
|
||||
COPY $TARGETPLATFORM/tomll /bin/tomll
|
||||
COPY $TARGETPLATFORM/tomljson /bin/tomljson
|
||||
COPY $TARGETPLATFORM/jsontoml /bin/jsontoml
|
||||
|
||||
@@ -301,73 +301,6 @@ OtherMissing = 1
|
||||
assert.Equal(t, 2, len(strictErr.Unwrap()))
|
||||
}
|
||||
|
||||
func TestDecodeError_PositionAfterComment(t *testing.T) {
|
||||
// Regression test for https://github.com/pelletier/go-toml/issues/1047
|
||||
// Error positions must be correct when the error occurs after comments or
|
||||
// other content that was already scanned past.
|
||||
examples := []struct {
|
||||
desc string
|
||||
doc string
|
||||
expectedRow int
|
||||
expectedCol int
|
||||
expectedStr string
|
||||
}{
|
||||
{
|
||||
desc: "invalid key after comment",
|
||||
doc: "# comment\n= \"value\"",
|
||||
expectedRow: 2,
|
||||
expectedCol: 1,
|
||||
expectedStr: "1| # comment\n2| = \"value\"\n | ~ invalid character at start of key: =",
|
||||
},
|
||||
{
|
||||
desc: "invalid key after two comments",
|
||||
doc: "# one\n# two\n= \"value\"",
|
||||
expectedRow: 3,
|
||||
expectedCol: 1,
|
||||
expectedStr: "1| # one\n2| # two\n3| = \"value\"\n | ~ invalid character at start of key: =",
|
||||
},
|
||||
{
|
||||
desc: "invalid key after key-value pair",
|
||||
doc: "a = 1\n= 2",
|
||||
expectedRow: 2,
|
||||
expectedCol: 1,
|
||||
expectedStr: "1| a = 1\n2| = 2\n | ~ invalid character at start of key: =",
|
||||
},
|
||||
{
|
||||
desc: "invalid key after blank line",
|
||||
doc: "a = 1\n\n= 2",
|
||||
expectedRow: 3,
|
||||
expectedCol: 1,
|
||||
expectedStr: "1| a = 1\n2|\n3| = 2\n | ~ invalid character at start of key: =",
|
||||
},
|
||||
}
|
||||
|
||||
for _, e := range examples {
|
||||
t.Run(e.desc, func(t *testing.T) {
|
||||
var v interface{}
|
||||
err := Unmarshal([]byte(e.doc), &v)
|
||||
if err == nil {
|
||||
t.Fatal("expected an error")
|
||||
}
|
||||
|
||||
var derr *DecodeError
|
||||
if !errors.As(err, &derr) {
|
||||
t.Fatalf("error not a *DecodeError: %T: %v", err, err)
|
||||
}
|
||||
|
||||
row, col := derr.Position()
|
||||
if row != e.expectedRow {
|
||||
t.Errorf("row: got %d, want %d (error: %s)", row, e.expectedRow, derr.String())
|
||||
}
|
||||
if col != e.expectedCol {
|
||||
t.Errorf("col: got %d, want %d (error: %s)", col, e.expectedCol, derr.String())
|
||||
}
|
||||
|
||||
assert.Equal(t, e.expectedStr, derr.String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func ExampleDecodeError() {
|
||||
doc := `name = 123__456`
|
||||
|
||||
|
||||
+3
-8
@@ -3,7 +3,6 @@ package unstable
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"unicode"
|
||||
|
||||
"github.com/pelletier/go-toml/v2/internal/characters"
|
||||
@@ -84,14 +83,10 @@ func (p *Parser) rangeOfToken(token, rest []byte) Range {
|
||||
}
|
||||
|
||||
// subsliceOffset returns the byte offset of subslice b within p.data.
|
||||
// b must be a subslice of p.data (sharing the same backing array).
|
||||
// b must be a suffix (tail) of p.data.
|
||||
func (p *Parser) subsliceOffset(b []byte) int {
|
||||
if len(b) == 0 {
|
||||
return 0
|
||||
}
|
||||
dataPtr := reflect.ValueOf(p.data).Pointer()
|
||||
subPtr := reflect.ValueOf(b).Pointer()
|
||||
return int(subPtr - dataPtr)
|
||||
// b is a suffix of p.data, so its offset is len(p.data) - len(b)
|
||||
return len(p.data) - len(b)
|
||||
}
|
||||
|
||||
// Raw returns the slice corresponding to the bytes in the given range.
|
||||
|
||||
Reference in New Issue
Block a user