mirror of
https://github.com/octoleo/restic.git
synced 2024-11-22 04:45:15 +00:00
restic: check that Node.LinkTarget can handle non-utf8 characters
This commit is contained in:
parent
6adb629608
commit
f12bbd9229
@ -2,6 +2,8 @@ package restic_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"reflect"
|
"reflect"
|
||||||
@ -10,6 +12,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/restic/restic/internal/restic"
|
"github.com/restic/restic/internal/restic"
|
||||||
|
"github.com/restic/restic/internal/test"
|
||||||
rtest "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 New Issue
Block a user