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

chore: parse escaped double colon (\\:) example struct tag #1402

Conversation

GusAntoniassi
Copy link
Contributor

Describe the PR
Replaces the regular string splitting by a ":" made during the "example" tag parsing so that it will not split escaped double colons, allowing string examples containing a double colon to be escaped using double backlashes.

Relation issue
#1401

Additional context
Since the core regexp library cannot suport negative lookaheads, I had to combine a regular expression with a loop to capture all the ocurrences and append them to an array.

Replaces the regular string splitting by a ":" made during
the "example" tag parsing so that it will not split escaped
double colons, allowing string examples containing a double
colon to be escaped using double backlashes.
@sdghchj
Copy link
Member

sdghchj commented Nov 29, 2022

I see your purpose is to make the map value contain colons.
But I wonder why not use a light mode to fix it, for example, use strings.IndexRune to find the first colon and split the string into two parts, a key and a value.

@GusAntoniassi
Copy link
Contributor Author

Hello @sdghchj, initially I went with this approach to allow escaped double colons in the key value, but thinking better about it it does not make much sense and I can't think of a valid use case for it.

I've refactored the code using strings.SplitN to split at the first ocurrence of a :, this makes the change much simpler and from my tests it won't be necessary to escape the remaining double colons in the value, so for example the struct from my issue would work without any changes:

type Foo struct {
  Attributes map[string]string `example:"bucket_arn:arn:aws:::foobar-bucket"`
}

@sdghchj sdghchj merged commit 8139731 into swaggo:master Nov 29, 2022
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.

None yet

2 participants