MCPcopy
hub / github.com/minio/minio-go / EncodePath

Function EncodePath

pkg/s3utils/utils.go:328–357  ·  view source on GitHub ↗

EncodePath encode the strings from UTF-8 byte representations to HTML hex escape sequences This is necessary since regular url.Parse() and url.Encode() functions do not support UTF-8 non english characters cannot be parsed due to the nature in which url.Encode() is written This function on the oth

(pathName string)

Source from the content-addressed store, hash-verified

326// This function on the other hand is a direct replacement for url.Encode() technique to support
327// pretty much every UTF-8 character.
328func EncodePath(pathName string) string {
329 if reservedObjectNames.MatchString(pathName) {
330 return pathName
331 }
332 var encodedPathname strings.Builder
333 for _, s := range pathName {
334 if 'A' <= s && s <= 'Z' || 'a' <= s && s <= 'z' || '0' <= s && s <= '9' { // §2.3 Unreserved characters (mark)
335 encodedPathname.WriteRune(s)
336 continue
337 }
338 switch s {
339 case '-', '_', '.', '~', '/': // §2.3 Unreserved characters (mark)
340 encodedPathname.WriteRune(s)
341 continue
342 default:
343 l := utf8.RuneLen(s)
344 if l < 0 {
345 // if utf8 cannot convert return the same string as is
346 return pathName
347 }
348 u := make([]byte, l)
349 utf8.EncodeRune(u, s)
350 for _, r := range u {
351 hex := hex.EncodeToString([]byte{r})
352 encodedPathname.WriteString("%" + strings.ToUpper(hex))
353 }
354 }
355 }
356 return encodedPathname.String()
357}
358
359// We support '.' with bucket names but we fallback to using path
360// style requests instead for such buckets.

Callers 9

makeTargetURLMethod · 0.92
MarshalMethod · 0.92
copyObjectDoMethod · 0.92
copyObjectPartDoMethod · 0.92
encodeURL2PathFunction · 0.92
PreSignV2Function · 0.92
getCanonicalRequestFunction · 0.92
TestEncodePathFunction · 0.85
QueryEncodeFunction · 0.85

Calls 2

EncodeToStringMethod · 0.80
StringMethod · 0.45

Tested by 1

TestEncodePathFunction · 0.68