Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:impl builtin:func to_base64 & fix from_base64 bug #3055

Closed
wants to merge 1 commit into from
Closed

fix:impl builtin:func to_base64 & fix from_base64 bug #3055

wants to merge 1 commit into from

Conversation

woodpenker
Copy link
Contributor

The mysql required:

Decoding recognizes and ignores newline, carriage return, tab, and space.

But go base64 func DecodeString() doesn't ignore tab ,space.

  • in tidb:
    select from_base64("YW Jj");
    ERROR 1105 (HY000): illegal base64 data at input byte 2
  • in mysql:
    select from_base64("YW Jj");
    +-----------------------+
    | from_base64("YW Jj") |
    +-----------------------+
    | abc |
    +-----------------------+

So I fix it && also I impl builtin:func to_base64(). I also add more test cases.

**the mysql required:
Decoding recognizes and ignores newline, carriage return, tab, and space.
the go base64  DecodeString() doesn't ignore tab ,space**
 -----
Also I impl builtin:func to_base64()
@hanfei1991 hanfei1991 added the contribution This PR is from a community contributor. label Apr 15, 2017
Copy link
Contributor

@tiancaiamao tiancaiamao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rest LGTM
Good job! @woodpenker

@@ -1795,7 +1797,46 @@ type builtinToBase64Sig struct {

// See https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_to-base64
func (b *builtinToBase64Sig) eval(row []types.Datum) (d types.Datum, err error) {
return d, errFunctionNotExists.GenByArgs("TO_BASE64")
//return d, errFunctionNotExists.GenByArgs("TO_BASE64")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove useless comment

}

//func to splite a string every n runes into a string[]
func splitToSubN(s string, n int) []string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After base64 encoding, all characters should never be UTF8 runes, so we can make this function simpler:

func splitToSubN(s string, n int) []string {
	subs := make([]string, 0, len(s)/n + 1)
	for len(s) > n {
		subs = append(subs, s[:n])
		s = s[n:]
	}
	subs = append(subs, s)
	return subs
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution This PR is from a community contributor.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants