"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
encoder: add option to encode . and .. names
Fabian Möllerd5cd026547ad
diff --git a/lib/encoder/encoder.go b/lib/encoder/encoder.goindex 7d5197dfa..f46cd8d63 100644--- a/lib/encoder/encoder.go+++ b/lib/encoder/encoder.go@@ -92,8 +92,22 @@ func (mask MultiEncoder) Encode(in string) string {encodeRightSpace = uint(mask)&EncodeRightSpace != 0encodeRightPeriod = uint(mask)&EncodeRightPeriod != 0encodeInvalidUnicode = uint(mask)&EncodeInvalidUtf8 != 0+ encodeDot = uint(mask)&EncodeDot != 0)+ if encodeDot {+ switch in {+ case ".":+ return "."+ case "..":+ return ".."+ case ".":+ return string(QuoteRune) + "."+ case "..":+ return string(QuoteRune) + "." + string(QuoteRune) + "."+ }+ }+// handle prefix only replacementsprefix := ""if encodeLeftSpace && len(in) > 0 { // Leading SPACE@@ -299,8 +313,22 @@ func (mask MultiEncoder) Decode(in string) string {encodeRightSpace = uint(mask)&EncodeRightSpace != 0encodeRightPeriod = uint(mask)&EncodeRightPeriod != 0encodeInvalidUnicode = uint(mask)&EncodeInvalidUtf8 != 0+ encodeDot = uint(mask)&EncodeDot != 0)+ if encodeDot {+ switch in {+ case ".":+ return "."+ case "..":+ return ".."+ case string(QuoteRune) + ".":+ return "."+ case string(QuoteRune) + "." + string(QuoteRune) + ".":+ return ".."+ }+ }+// handle prefix only replacementsprefix := ""if r, l1 := utf8.DecodeRuneInString(in); encodeLeftSpace && r == '␠' { // SYMBOL FOR SPACEdiff --git a/lib/encoder/encoder_test.go b/lib/encoder/encoder_test.goindex 889540663..7e9c34551 100644--- a/lib/encoder/encoder_test.go+++ b/lib/encoder/encoder_test.go@@ -102,6 +102,49 @@ func TestEncodeInvalidUnicode(t *testing.T) {})}}++func TestEncodeDot(t *testing.T) {+ for i, tc := range []testCase{+ {+ mask: 0,+ in: ".",+ out: ".",+ }, {+ mask: EncodeDot,+ in: ".",+ out: ".",+ }, {+ mask: 0,+ in: "..",+ out: "..",+ }, {+ mask: EncodeDot,+ in: "..",+ out: "..",+ }, {+ mask: EncodeDot,+ in: "...",+ out: "...",+ }, {+ mask: EncodeDot,+ in: ". .",+ out: ". .",+ },+ } {+ e := MultiEncoder(tc.mask)+ t.Run(strconv.FormatInt(int64(i), 10), func(t *testing.T) {+ got := e.Encode(tc.in)+ if got != tc.out {+ t.Errorf("Encode(%q) want %q got %q", tc.in, tc.out, got)+ }+ got2 := e.Decode(got)+ if got2 != tc.in {+ t.Errorf("Decode(%q) want %q got %q", got, tc.in, got2)+ }+ })+ }+}+func TestDecodeHalf(t *testing.T) {for i, tc := range []testCase{{