Replace periods underscore kong2tf#1756
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1756 +/- ##
==========================================
+ Coverage 32.85% 32.94% +0.08%
==========================================
Files 73 73
Lines 8053 8068 +15
==========================================
+ Hits 2646 2658 +12
- Misses 5243 5245 +2
- Partials 164 165 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| } | ||
|
|
||
| // slugify converts a string into a slug using underscores | ||
| func slugify(input string) string { |
There was a problem hiding this comment.
This would still allow characters like @, # to go through, but terraform does not allow in resource names.
Kong allows these in the entity names though.
What if we do something like this using unicode package -
| func slugify(input string) string { | |
| func keepRuneUnicode(r rune) rune { | |
| if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '_' || r == '-' { | |
| return r | |
| } | |
| return '_' | |
| } | |
| func slugify(input string) string { | |
| slug := strings.Map(keepRuneUnicode, input) | |
| // Remove any consecutive underscores | |
| for strings.Contains(slug, "__") { | |
| slug = strings.ReplaceAll(slug, "__", "_") | |
| } | |
| // Trim leading and trailing underscores | |
| slug = strings.Trim(slug, "_") | |
| return slug | |
| } |
This would replace all disallowed characters with _
There was a problem hiding this comment.
This works for me. Can you commit + add any additional test cases you think are important?
There was a problem hiding this comment.
I've added tests and this change in 40b4b33, will merge if looks good.
Resolves #1752