diff --git a/handler-details.go b/handler-details.go index e23773340886a1a48f3c41373295f21bcd09e42d..721ff0d6d6cc5bbc0f3bbc3e0e88d15c6f3fbc81 100644 --- a/handler-details.go +++ b/handler-details.go @@ -98,7 +98,7 @@ func (h Handler) detailsPost(w http.ResponseWriter, r *http.Request) { return } - country, err := ISO3CountryFromString(r.FormValue("country")) + country, err := ISO2CountryCodeFromString(r.FormValue("country")) if err != nil { httpError(w, "can't parse country", nil, http.StatusBadRequest) return diff --git a/vino.go b/vino.go index 3b0226c0775574bfb1ec06414525f0384b02c02e..d33f4f5eb458d4d01faa5fccb62b0990c477737b 100644 --- a/vino.go +++ b/vino.go @@ -32,7 +32,7 @@ type ISO2CountryCode [2]byte var UnknownCountry = ISO2CountryCode{'X', 'X'} -func ISO3CountryFromString(s string) (ISO2CountryCode, error) { +func ISO2CountryCodeFromString(s string) (ISO2CountryCode, error) { if len(s) == 0 { return UnknownCountry, nil } @@ -45,6 +45,10 @@ func ISO3CountryFromString(s string) (ISO2CountryCode, error) { } func (i ISO2CountryCode) String() string { + if i[0] == 0 || i[1] == 0 { + return "XX" + } + return fmt.Sprintf("%c%c", i[0], i[1]) } @@ -59,7 +63,7 @@ func (i *ISO2CountryCode) UnmarshalBinary(d []byte) error { return nil } - *i = ISO2CountryCode{d[0], d[1]} + copy(i[:], d) return nil }