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)
| 326 | // This function on the other hand is a direct replacement for url.Encode() technique to support |
| 327 | // pretty much every UTF-8 character. |
| 328 | func 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. |