Skip to content

Commit

Permalink
fix base64_decode
Browse files Browse the repository at this point in the history
  • Loading branch information
syyongx committed Apr 22, 2019
1 parent f353456 commit 31bd564
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions php.go
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,12 @@ func Base64Encode(str string) string {

// Base64Decode base64_decode()
func Base64Decode(str string) (string, error) {
switch len(str) % 4 {
case 2:
str += "=="
case 3:
str += "="
}
data, err := base64.StdEncoding.DecodeString(str)
if err != nil {
return "", err
Expand Down
2 changes: 1 addition & 1 deletion php_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func TestUrl(t *testing.T) {
tBase64Encode := Base64Encode("This is an encoded string")
equal(t, "VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==", tBase64Encode)

tBase64Decode, _ := Base64Decode("VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==")
tBase64Decode, _ := Base64Decode("VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw")
equal(t, "This is an encoded string", tBase64Decode)

tHTTPBuildQuery := HTTPBuildQuery(map[string][]string{"first": []string{"value"}, "multi": []string{"foo bar", "baz"}})
Expand Down

0 comments on commit 31bd564

Please sign in to comment.