Skip to content

fix: support escaped commas in struct tag options - #30

Open
AdamMagued wants to merge 1 commit into
fatih:masterfrom
AdamMagued:fix-issue-21-escaped-commas-in-options
Open

AdamMagued wants to merge 1 commit into
fatih:masterfrom
AdamMagued:fix-issue-21-escaped-commas-in-options

Conversation

@AdamMagued

Copy link
Copy Markdown

Fixes #21.

Summary

When parsing struct tag values, Parse() previously used strings.Split(value, ","). This unconditionally split tag values on any comma, breaking options that contained escaped commas (such as regular expressions or descriptive text like description=A reason, hopefully a valid one).

Changes

  • Replaced unconditional strings.Split in Parse() with a custom split function that respects backslash-escaped commas. An odd number of preceding backslashes denotes an escaped comma, whereas an even number treats the comma as an option delimiter.
  • Added comprehensive unit tests in TestParse and TestTags_EscapedCommas covering escaped commas in options, regex patterns, tag names, multiple escaped commas, and escaped backslashes preceding commas.

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 this pull request may close these issues.

Options with quoted ',' signs are mangled during Parse()

1 participant