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

[encoder] fix zero len array decoding #20

Merged
merged 1 commit into from
Mar 27, 2018

Conversation

playboyko
Copy link

  • strings.Split with empty slice argument returns slice with 1 element
    which is empty string. without check len decoder crashes on empty
    numeric arrays
  • encoder test added
  • types test added

encoder.go Outdated
@@ -136,6 +136,10 @@ func (d *textDecoder) Decode(t string, value []byte) (driver.Value, error) {
if strings.HasPrefix(t, "Array") {
if len(v) > 0 && v[0] == '[' && v[len(value)-1] == ']' {
items := strings.Split(v[1:len(value)-1], ",")
Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for PR.
I think the following construction will be better:

if len(v) > 0 && v[0] == '[' && v[len(v)-1] == '] {
    var items []string
    // check that array is not empty ([])
    if len(v) > 2 {
        items = strings.Split(v[1:len(v)-1], ",")
    }

@bgaifullin
Copy link
Contributor

Thank you. the patch looks good to me.

Could you also stash your commits, by using command git rebase -i HEAD^^ ?
because the second commit it is just some fix for first commit.

- strings.Split with empty slice argument returns slice with 1 element
which is empty string. without check len decoder crashes on empty
numeric arrays
- encoder test added
- types test added
@playboyko
Copy link
Author

@bgaifullin Could you please check if everything is ok now?

@bgaifullin
Copy link
Contributor

Thanks.

@bgaifullin bgaifullin merged commit 7cb83a2 into mailru:master Mar 27, 2018
@bgaifullin
Copy link
Contributor

merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants