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

Add support for groupArray(String) #43

Merged
merged 12 commits into from
Sep 21, 2018
Merged

Conversation

arkie
Copy link
Contributor

@arkie arkie commented Sep 7, 2018

This PR updates the decode function to split on comma surrounded by quotes instead of only comma for string arrays in order to avoid splitting inside of the returned value (updated test to demonstrate).

@bgaifullin
Copy link
Contributor

Please add a short description, what is the purpose of this PR

encoder_test.go Outdated
@@ -83,6 +83,7 @@ func TestTextDecoder(t *testing.T) {
{"Enum16('one'=1)", "'one'", "one"},
{"Array(UInt32)", "[1,2]", []uint32{1, 2}},
{"Array(UInt32)", "[]", []uint32{}},
{"Array(String)", "['one','one\\'']", []string{"one", "one'"}},
Copy link
Contributor

Choose a reason for hiding this comment

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

this test passes on current HEAD without patch for method func (d *textDecoder) Decode(t string, value []byte) (driver.Value, error)

@arkie
Copy link
Contributor Author

arkie commented Sep 17, 2018

@bgaifullin update the test to actually show the issue 👍

encoder.go Outdated
if len(v) > 2 {
// check if array is string encoded (['example'])
if len(v) > 4 && v[1] == '\'' && v[len(v)-2] == '\'' {
items = strings.Split(v[2:len(v)-2], "','")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think fix should be a little be more complicated, otherwise it brokes the parsing arrays of Datetime.
Need to check that subtype is String or FixedString and need to unescape for each item of array of strings.

@arkie
Copy link
Contributor Author

arkie commented Sep 19, 2018

@bgaifullin Should be good for another look

Copy link
Contributor

@bgaifullin bgaifullin left a comment

Choose a reason for hiding this comment

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

Very good, thank you.
several little comments

encoder.go Outdated
// check that array is not empty ([])
if len(v) > 2 {
subType := t[6 : len(t)-1]
// check if array is string encoded (['example'])
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO: check if array of strings and not empty will be a little bit clearly

encoder.go Outdated
for i, v := range items {
items[i] = unescape(v)
}
} else if len(v) > 2 { // check that array is not empty ([])
Copy link
Contributor

Choose a reason for hiding this comment

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

IMHO, this condition can be checked at first, before all other staff.

  • check that array is not empty.
  • check that array of strings
  • other cases

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to what I think you had in mind? If not, if you want to include the ifs, am happy to add into PR.

@bgaifullin
Copy link
Contributor

LGTM, thanks

@bgaifullin bgaifullin merged commit fb4335c into mailru:master Sep 21, 2018
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.

2 participants