MCPcopy
hub / github.com/rclone/rclone / TestFileNameEncoding

Function TestFileNameEncoding

backend/huaweidrive/huaweidrive_test.go:182–240  ·  view source on GitHub ↗

TestFileNameEncoding tests that problematic characters are properly encoded

(t *testing.T)

Source from the content-addressed store, hash-verified

180
181// TestFileNameEncoding tests that problematic characters are properly encoded
182func TestFileNameEncoding(t *testing.T) {
183 // Create a mock Fs with default encoding options
184 opts := Options{}
185 // Set the default encoding from our config
186 opts.Enc = (encoder.Display |
187 encoder.EncodeBackSlash |
188 encoder.EncodeInvalidUtf8 |
189 encoder.EncodeRightSpace |
190 encoder.EncodeLeftSpace |
191 encoder.EncodeLeftTilde |
192 encoder.EncodeRightPeriod |
193 encoder.EncodeLeftPeriod |
194 encoder.EncodeColon |
195 encoder.EncodePipe |
196 encoder.EncodeDoubleQuote |
197 encoder.EncodeLtGt |
198 encoder.EncodeQuestion |
199 encoder.EncodeAsterisk |
200 encoder.EncodeCtl |
201 encoder.EncodeDot)
202
203 f := &Fs{opt: opts}
204
205 // Test problematic characters that Huawei Drive rejects
206 testCases := []struct {
207 input string
208 desc string
209 }{
210 {`file<name>.txt`, "angle brackets"},
211 {`file|name.txt`, "pipe character"},
212 {`file:name.txt`, "colon"},
213 {`file"name.txt`, "double quote"},
214 {`file*name.txt`, "asterisk"},
215 {`file?name.txt`, "question mark"},
216 {`file\name.txt`, "backslash"},
217 {` leading_space.txt`, "leading space"},
218 {`trailing_space.txt `, "trailing space"},
219 {`.leading_dot.txt`, "leading dot"},
220 {`trailing_dot.txt.`, "trailing dot"},
221 {`~leading_tilde.txt`, "leading tilde"},
222 {"file\x00name.txt", "control character"},
223 }
224
225 for _, tc := range testCases {
226 encoded := f.opt.Enc.FromStandardName(tc.input)
227 // The encoded name should be different from input (meaning it was encoded)
228 if encoded == tc.input {
229 t.Errorf("Expected %s (%q) to be encoded, but got same string", tc.desc, tc.input)
230 }
231
232 // Test that we can decode it back (skip control characters as they are not reversible)
233 decoded := f.opt.Enc.ToStandardName(encoded)
234 if tc.desc != "control character" && decoded != tc.input {
235 t.Errorf("Round-trip failed for %s: input=%q, encoded=%q, decoded=%q", tc.desc, tc.input, encoded, decoded)
236 }
237
238 t.Logf("✓ %s: %q → %q → %q", tc.desc, tc.input, encoded, decoded)
239 }

Callers

nothing calls this directly

Calls 4

LogfMethod · 0.80
FromStandardNameMethod · 0.65
ToStandardNameMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…