Skip to content

Assumption about struct tag keys uniqueness could break code #37

@glumia

Description

@glumia
$ cat struct_tag.go
package fixtures

type MyEntity struct {
        tableName struct{} `myTag:"value1" myTag:"value2"`
}
$ golines struct_tag.go
package fixtures

type MyEntity struct {
        tableName struct{} `myTag:"value1"`
}

Suppose that myLibrary's tag parser has the behaviour of appending values when a tag key is repeated (myTag:"value1" myTag:"value2" -> "value1,value2"), golines in this case will break my code.

I know that this isn't the behaviour of reflect (its Get method on the tag would take just the first value) but Go doesn't enforce any constraint on the syntax of struct tags so we can't know what people out there do with them.

This issue is caused by the assumption that struct tags always comply with the convention described in https://pkg.go.dev/reflect#StructTag (thus that tag keys are unique) in alignTags [code].

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions