mirror of
https://github.com/restic/restic.git
synced 2026-06-13 04:19:45 +00:00
Correctly encode non utf8 node names
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package restic
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
@@ -367,6 +368,28 @@ func (node Node) SameContent(olderNode *Node) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (node Node) MarshalJSON() ([]byte, error) {
|
||||
type nodeJSON Node
|
||||
nj := nodeJSON(node)
|
||||
name := strconv.Quote(node.Name)
|
||||
nj.Name = name[1 : len(name)-1]
|
||||
|
||||
return json.Marshal(nj)
|
||||
}
|
||||
|
||||
func (node *Node) UnmarshalJSON(data []byte) error {
|
||||
type nodeJSON Node
|
||||
var nj *nodeJSON = (*nodeJSON)(node)
|
||||
|
||||
err := json.Unmarshal(data, nj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
nj.Name, err = strconv.Unquote(`"` + nj.Name + `"`)
|
||||
return err
|
||||
}
|
||||
|
||||
func (b Blob) Free() {
|
||||
if b.ID != nil {
|
||||
b.ID.Free()
|
||||
|
||||
Reference in New Issue
Block a user