-
Notifications
You must be signed in to change notification settings - Fork 2k
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
INS-2627: sanitize path-variable name regex capture for kong 3.x #5958
INS-2627: sanitize path-variable name regex capture for kong 3.x #5958
Conversation
if (result.startsWith('_')) { | ||
result = 'a' + result; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we externalize this in to its own function? that function can then be called from here, as well as from the validation-generator, to ensure both will have the same name, and the user doesn't have to manually update his/her OAS spec
here's the Go-function; https://github.com/Kong/go-apiops/blob/8842f7b0ecf3654f62f8e0bd867b5b67766794c9/convertoas3/oas3.go#L47-L57
called when generating the regex: https://github.com/Kong/go-apiops/blob/8842f7b0ecf3654f62f8e0bd867b5b67766794c9/convertoas3/oas3.go#L819
called when generating the validation: https://github.com/Kong/go-apiops/blob/8842f7b0ecf3654f62f8e0bd867b5b67766794c9/convertoas3/validator.go#L60-L64
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, moved it into it's own function, and has the same name 👍
// Remove illegal chars from path-variable name. | ||
// see https://github.com/Kong/go-apiops/blob/8842f7b0ecf3654f62f8e0bd867b5b67766794c9/convertoas3/oas3.go#L50 | ||
if (!legacy) { | ||
result = result.replace(/-/g, '_'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To do this properly, use some slugification (to fix non-ascii chars), and then reduce to [A-Za-z0-9_] whilst starting with [A-Za-z].
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from: https://www.pcre.org/current/doc/html/pcre2pattern.html#SEC16
When PCRE2_UTF is not set, they may contain only ASCII alphanumeric characters and underscores, but must start with a non-digit.
I don't know if PCRE2_UTF is set in our implementation, but better safe than sorry I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added slugification is done ✅
The PCRE2_UTF part not sure how to do it though, but should be fine as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what I meant mostly was removing accents etc from characters; eg. reduce èëé
into eee
6a9a206
to
2708d6c
Compare
Closes INS-2627
Closes FTI-5060
changelog(Fixes): Added a fix to handle an edge of how path variable names are captured from regex when parsing OAS specs for Kong 3.x.
Minor change, to mimic what was done in
kced
- see https://github.com/Kong/go-apiops/blob/8842f7b0ecf3654f62f8e0bd867b5b67766794c9/convertoas3/oas3.go#L50