forked from TrueCloudLab/restic
restic: check that Node.LinkTarget can handle non-utf8 characters
This commit is contained in:
parent
6adb629608
commit
f12bbd9229
1 changed files with 38 additions and 0 deletions
|
@ -2,6 +2,8 @@ package restic_test
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
|
@ -10,6 +12,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/restic"
|
||||
"github.com/restic/restic/internal/test"
|
||||
rtest "github.com/restic/restic/internal/test"
|
||||
)
|
||||
|
||||
|
@ -334,3 +337,38 @@ func TestFixTime(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSymlinkSerialization(t *testing.T) {
|
||||
for _, link := range []string{
|
||||
"válîd \t Üñi¢òde \n śẗŕinǵ",
|
||||
string([]byte{0, 1, 2, 0xfa, 0xfb, 0xfc}),
|
||||
} {
|
||||
n := restic.Node{
|
||||
LinkTarget: link,
|
||||
}
|
||||
ser, err := json.Marshal(n)
|
||||
test.OK(t, err)
|
||||
var n2 restic.Node
|
||||
err = json.Unmarshal(ser, &n2)
|
||||
test.OK(t, err)
|
||||
fmt.Println(string(ser))
|
||||
|
||||
test.Equals(t, n.LinkTarget, n2.LinkTarget)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSymlinkSerializationFormat(t *testing.T) {
|
||||
for _, d := range []struct {
|
||||
ser string
|
||||
linkTarget string
|
||||
}{
|
||||
{`{"linktarget":"test"}`, "test"},
|
||||
{`{"linktarget":"\u0000\u0001\u0002\ufffd\ufffd\ufffd","linktarget_raw":"AAEC+vv8"}`, string([]byte{0, 1, 2, 0xfa, 0xfb, 0xfc})},
|
||||
} {
|
||||
var n2 restic.Node
|
||||
err := json.Unmarshal([]byte(d.ser), &n2)
|
||||
test.OK(t, err)
|
||||
test.Equals(t, d.linkTarget, n2.LinkTarget)
|
||||
test.Assert(t, n2.LinkTargetRaw == nil, "quoted link target is just a helper field and must be unset after decoding")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue