1
0
mirror of https://github.com/rclone/rclone.git synced 2025-11-23 21:44:49 +02:00

lib/encoder: add encoding of square brackets

This commit is contained in:
Ivan Andreev
2021-06-23 17:05:39 +03:00
parent 69f4b48719
commit 48e7246163
4 changed files with 28871 additions and 26586 deletions

View File

@@ -280,6 +280,7 @@ will show you the defaults for the backends.
| RightSpace | SPACE on the right of a string |
| SingleQuote | `'` |
| Slash | `/` |
| SquareBracket | `[`, `]` |
To take a specific example, the FTP backend's default encoding is

View File

@@ -63,6 +63,7 @@ const (
EncodeRightCrLfHtVt // Trailing CR LF HT VT
EncodeInvalidUtf8 // Invalid UTF-8 bytes
EncodeDot // . and .. names
EncodeSquareBracket // []
// Synthetic
EncodeWin = EncodeColon | EncodeQuestion | EncodeDoubleQuote | EncodeAsterisk | EncodeLtGt | EncodePipe // :?"*<>|
@@ -120,6 +121,7 @@ func init() {
alias("None", EncodeZero)
alias("Slash", EncodeSlash)
alias("LtGt", EncodeLtGt)
alias("SquareBracket", EncodeSquareBracket)
alias("DoubleQuote", EncodeDoubleQuote)
alias("SingleQuote", EncodeSingleQuote)
alias("BackQuote", EncodeBackQuote)
@@ -315,6 +317,13 @@ func (mask MultiEncoder) Encode(in string) string {
return true
}
}
if mask.Has(EncodeSquareBracket) { // []
switch r {
case '[', ']',
'[', ']':
return true
}
}
if mask.Has(EncodeQuestion) { // ?
switch r {
case '?',
@@ -473,6 +482,17 @@ func (mask MultiEncoder) Encode(in string) string {
continue
}
}
if mask.Has(EncodeSquareBracket) { // []
switch r {
case '[', ']':
out.WriteRune(r + fullOffset)
continue
case '[', ']':
out.WriteRune(QuoteRune)
out.WriteRune(r)
continue
}
}
if mask.Has(EncodeQuestion) { // ?
switch r {
case '?':
@@ -713,6 +733,13 @@ func (mask MultiEncoder) Decode(in string) string {
return true
}
}
if mask.Has(EncodeSquareBracket) { // []
switch r {
case '[', ']':
return true
}
}
if mask.Has(EncodeQuestion) { // ?
switch r {
case '?':
@@ -857,6 +884,17 @@ func (mask MultiEncoder) Decode(in string) string {
continue
}
}
if mask.Has(EncodeSquareBracket) { // []
switch r {
case '[', ']':
if unquote {
out.WriteRune(r)
} else {
out.WriteRune(r - fullOffset)
}
continue
}
}
if mask.Has(EncodeQuestion) { // ?
switch r {
case '?':

File diff suppressed because it is too large Load Diff

View File

@@ -42,6 +42,7 @@ var maskBits = []struct {
{encoder.EncodeSingleQuote, "EncodeSingleQuote"},
{encoder.EncodeBackQuote, "EncodeBackQuote"},
{encoder.EncodeLtGt, "EncodeLtGt"},
{encoder.EncodeSquareBracket, "EncodeSquareBracket"},
{encoder.EncodeDollar, "EncodeDollar"},
{encoder.EncodeDoubleQuote, "EncodeDoubleQuote"},
{encoder.EncodeColon, "EncodeColon"},
@@ -105,6 +106,11 @@ var allMappings = []mapping{{
}, []rune{
'<', '>',
}}, {
encoder.EncodeSquareBracket, []rune{
'[', ']',
}, []rune{
'[', ']',
}}, {
encoder.EncodeDoubleQuote, []rune{
'"',
}, []rune{