-
Notifications
You must be signed in to change notification settings - Fork 588
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
ToValue converting array into map[string]interface{} #24
Comments
If I call |
Sorry about that. The problem is (probably) around here: https://github.com/robertkrimen/otto/blob/master/value.go#L625 This is the commit that "broke" it: We have different types for a Go slice versus a Go array, now. I'm not sure exactly why the export tests did not catch this, though... |
Maybe line 628 should read if object.class == "Array” || object.class == “GoArray” { ? |
Yeah, that fixed it. |
The bug isn't fixed. My test is still failing — it's that assertion that I commented out when pasting it above. The result of Export is now correctly a string array, but unfortunately its value is nil :(
The unit test you added (Test_issue24) doesn't catch this because it only verifies the return type, not the actual value. |
Oops, never mind — my own code was broken (it was still expecting Value to return []interface{}, not []string!) |
Make sure we get back out what we put in.
The latest Otto revisions break the Couchbase Sync Gateway -- it's more trouble decoding Otto values to Go string arrays. This time the problem is that ToValue returns not a Go []string but a map[string]interface{} where the keys are stringified array indexes, i.e. it looks like {"0":"foo", "1":"bar", "2":"baz"} instead of ["foo", "bar", "baz"].
This hits the Printf call, which logs:
Of course it's also possible that ToValue is converting the Go array into a JS object with integer keys; I know that in JS there's a very subtle distinction between arrays and objects.
The text was updated successfully, but these errors were encountered: