(ctx context.Context, parts []string)
| 23 | } |
| 24 | |
| 25 | func (p *Parser) decodeBase64URL(ctx context.Context, parts []string) (string, string, error) { |
| 26 | var format string |
| 27 | |
| 28 | if len(parts) > 1 && p.config.Base64URLIncludesFilename { |
| 29 | parts = parts[:len(parts)-1] |
| 30 | } |
| 31 | |
| 32 | encoded := strings.Join(parts, "") |
| 33 | urlParts := strings.Split(encoded, ".") |
| 34 | |
| 35 | if len(urlParts[0]) == 0 { |
| 36 | return "", "", newInvalidURLError(ctx, "Image URL is empty") |
| 37 | } |
| 38 | |
| 39 | if len(urlParts) > 2 { |
| 40 | return "", "", newInvalidURLError(ctx, "Multiple formats are specified: %s", encoded) |
| 41 | } |
| 42 | |
| 43 | if len(urlParts) == 2 && len(urlParts[1]) > 0 { |
| 44 | format = urlParts[1] |
| 45 | } |
| 46 | |
| 47 | imageURL, err := base64.RawURLEncoding.DecodeString(strings.TrimRight(urlParts[0], "=")) |
| 48 | if err != nil { |
| 49 | return "", "", newInvalidURLError(ctx, "Invalid url encoding: %s", encoded) |
| 50 | } |
| 51 | |
| 52 | return p.preprocessURL(string(imageURL)), format, nil |
| 53 | } |
| 54 | |
| 55 | func (p *Parser) decodePlainURL(ctx context.Context, parts []string) (string, string, error) { |
| 56 | var format string |
no test coverage detected