Skip to content

Instantly share code, notes, and snippets.

@ethanfrey
Created May 12, 2017 21:56
Show Gist options
  • Save ethanfrey/ca2263c91a172cf5e00ec9233f0f6dca to your computer and use it in GitHub Desktop.
Save ethanfrey/ca2263c91a172cf5e00ec9233f0f6dca to your computer and use it in GitHub Desktop.
package bug
import (
"encoding/base64"
"testing"
)
func TestWTF(t *testing.T) {
assert := assert.New(t)
url := base64.URLEncoding
std := base64.StdEncoding
cases := []struct {
s string
e *base64.Encoding
}{
// these fail...
{"D4_a--1=", url},
{"D4_a0-1=", url},
{"D4_a__1=", url},
{"D4/a++1=", std},
{"D4_a0-9=", url},
{"Finey-1=", url},
{"Finey41=", url},
{"Finey+1=", std},
{"Finey+1+", std},
{"Fineyo1=", url},
// these work
{"D4_a0-A=", url},
{"D4_a0BA=", url},
// more random ending in [1-9]=
{"deadbe7=", url},
{"deadb7==", url},
{"deadbe==", url},
// wait, 0= is safe...
{"deadbe0=", url},
{"deadAA2=", std},
{"deadAA9=", std},
{"deadaa9=", url},
}
for _, tc := range cases {
b, err := tc.e.DecodeString(tc.s)
if assert.Nil(err, "%#v", err) {
s := tc.e.EncodeToString(b)
assert.Equal(tc.s, s)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment