|
@@ -2,7 +2,6 @@ package options
|
|
|
|
|
|
import (
|
|
|
"encoding/base64"
|
|
|
- "errors"
|
|
|
"fmt"
|
|
|
"net/url"
|
|
|
"strings"
|
|
@@ -35,11 +34,11 @@ func decodeBase64URL(parts []string) (string, string, error) {
|
|
|
urlParts := strings.Split(encoded, ".")
|
|
|
|
|
|
if len(urlParts[0]) == 0 {
|
|
|
- return "", "", errors.New("Image URL is empty")
|
|
|
+ return "", "", newInvalidURLError("Image URL is empty")
|
|
|
}
|
|
|
|
|
|
if len(urlParts) > 2 {
|
|
|
- return "", "", fmt.Errorf("Multiple formats are specified: %s", encoded)
|
|
|
+ return "", "", newInvalidURLError("Multiple formats are specified: %s", encoded)
|
|
|
}
|
|
|
|
|
|
if len(urlParts) == 2 && len(urlParts[1]) > 0 {
|
|
@@ -48,7 +47,7 @@ func decodeBase64URL(parts []string) (string, string, error) {
|
|
|
|
|
|
imageURL, err := base64.RawURLEncoding.DecodeString(strings.TrimRight(urlParts[0], "="))
|
|
|
if err != nil {
|
|
|
- return "", "", fmt.Errorf("Invalid url encoding: %s", encoded)
|
|
|
+ return "", "", newInvalidURLError("Invalid url encoding: %s", encoded)
|
|
|
}
|
|
|
|
|
|
return preprocessURL(string(imageURL)), format, nil
|
|
@@ -61,11 +60,11 @@ func decodePlainURL(parts []string) (string, string, error) {
|
|
|
urlParts := strings.Split(encoded, "@")
|
|
|
|
|
|
if len(urlParts[0]) == 0 {
|
|
|
- return "", "", errors.New("Image URL is empty")
|
|
|
+ return "", "", newInvalidURLError("Image URL is empty")
|
|
|
}
|
|
|
|
|
|
if len(urlParts) > 2 {
|
|
|
- return "", "", fmt.Errorf("Multiple formats are specified: %s", encoded)
|
|
|
+ return "", "", newInvalidURLError("Multiple formats are specified: %s", encoded)
|
|
|
}
|
|
|
|
|
|
if len(urlParts) == 2 && len(urlParts[1]) > 0 {
|
|
@@ -74,7 +73,7 @@ func decodePlainURL(parts []string) (string, string, error) {
|
|
|
|
|
|
unescaped, err := url.PathUnescape(urlParts[0])
|
|
|
if err != nil {
|
|
|
- return "", "", fmt.Errorf("Invalid url encoding: %s", encoded)
|
|
|
+ return "", "", newInvalidURLError("Invalid url encoding: %s", encoded)
|
|
|
}
|
|
|
|
|
|
return preprocessURL(unescaped), format, nil
|
|
@@ -82,7 +81,7 @@ func decodePlainURL(parts []string) (string, string, error) {
|
|
|
|
|
|
func DecodeURL(parts []string) (string, string, error) {
|
|
|
if len(parts) == 0 {
|
|
|
- return "", "", errors.New("Image URL is empty")
|
|
|
+ return "", "", newInvalidURLError("Image URL is empty")
|
|
|
}
|
|
|
|
|
|
if parts[0] == urlTokenPlain && len(parts) > 1 {
|