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

x = [] decodes into nil #338

Closed
dtcaciuc opened this issue Jan 11, 2022 · 1 comment · Fixed by #339
Closed

x = [] decodes into nil #338

dtcaciuc opened this issue Jan 11, 2022 · 1 comment · Fixed by #339

Comments

@dtcaciuc
Copy link
Contributor

dtcaciuc commented Jan 11, 2022

The following program works differently between 0.3.1 and 0.4.1:

package main

import (
    "log"
    "reflect"

    "github.com/BurntSushi/toml"
)

func main() {
    blob := `
    x = []
    `
    var d map[string]interface{}
    if _, err := toml.Decode(blob, &d); err != nil {
        log.Fatal(err)
    }

    x := d["x"]
    log.Println(x, reflect.ValueOf(x).IsNil())
}

On 0.3.1,

[] false

On 0.4.1,

[] true

For my use case, this is a problem because I'm subsequently encoding the value into JSON and it writes x = null instead of the expected x = []. It also goes deeper than that, for instance x = [[]] would get JSONed as x = [null].

Is this an intended change? Do you think it would be possible/correct to restore the previous behaviour?

@arp242
Copy link
Collaborator

arp242 commented Jan 11, 2022

It's not really an intentional change, as far as I can recall.

It's really the encoding/json behaviour that's problematic; it's a long-standing issue. I'll probably fix it eventually, but it might be a while. I'll review and merge PRs though.

dtcaciuc added a commit to dtcaciuc/toml that referenced this issue Jan 12, 2022
This restores v0.3 behaviour and also makes it
consistent with how the same decodes into something
like struct { S []string }.

Closes BurntSushi#338
arp242 pushed a commit that referenced this issue Jan 12, 2022
This restores v0.3 behaviour and also makes it
consistent with how the same decodes into something
like struct { S []string }.

Closes #338
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 a pull request may close this issue.

2 participants