Skip to content

Number in string field interpreted as octal #631

@zfLQ2qx2

Description

@zfLQ2qx2

I have a golang structure:

type AWSAccounts struct {
        AccountID  string `yaml:"accountid,omitempty"`
        Nickname   string `yaml:"nickname,omitempty"`
        RoleARN    string `yaml:"rolearn,omitempty"`
        ExternalID string `yaml:"externalid,omitempty"`
}

And I have an element like this (not the real account number but shows the issue):

  - accountid: 074763617300
    nickname: 'xxx-xxx'
    rolearn: arn:aws:iam::074763617300:role/IAM_ROLE

Even though accountid is a string, the value is being interpreted as an octal number. The workaround is to quote the value - however this deviates in behavior from gopkg.in/yaml.v3 which treats it as a string without the explicit quoting. The encoding/json package does not have the same issue because its quoting rules are more rigid. I don't know if this is a case of gopkg.in/yaml.v3 being too loose or goccy/go-yaml not being flexible enough, but it is completely reproducible. I did also note that if the number is large enough that it would overflow if interpreted as an integer, then it does get interpreted as a string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions