fatih / structtag

Parse and modify Go struct field tags
Other
633 stars 39 forks source link

trailing space causes Parse to return nothing #8

Closed stephens2424 closed 4 years ago

stephens2424 commented 5 years ago

A trailing space in a struct tag, like `json:"foo" `, causes the parse result to be nil, nil. I would expect the trailing space to be ignored.

For example: https://play.golang.org/p/NgGis4SV2mY

I'm filing this issue for tracking, but I also have a patch to submit.

fatih commented 4 years ago

Thanks for the feedback The parsing code is part of the Go source code and hence I'm not sure if this is a feature or bug.

stephens2424 commented 4 years ago

Thanks for the response. It looks like the reflect package handles the trailing spaces. Checking out the reflect source, it looks like it uses a break out of that loop as well, like with my change. I can't say I understand why the difference exists, though, so maybe there's something I'm missing, but maybe these data points help.

fatih commented 4 years ago

This makes sense, thanks for the looking into it more detailed. The tests are also passing so there is no issues going forward. I merged your change and will release a new version.