1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-08-06 17:40:58 +00:00

fix: sanitize network aliases to be valid DNS names (part 2) (#197)

- prefer the lowercase version of the DNS name which is more common they are case insensitive anyway
- fix the inverted information when sanitation happens

Reviewed-on: https://code.forgejo.org/forgejo/act/pulls/197
Reviewed-by: msrd0 <msrd0@noreply.code.forgejo.org>
Co-authored-by: Earl Warren <contact@earl-warren.org>
Co-committed-by: Earl Warren <contact@earl-warren.org>
This commit is contained in:
Earl Warren 2025-07-26 11:31:05 +00:00 committed by earl-warren
parent b1ea5424b9
commit 28c639e48b
2 changed files with 6 additions and 6 deletions

View file

@ -402,13 +402,13 @@ func (rc *RunContext) getNetworkName(_ context.Context) (networkName string, cre
return networkName, createAndDeleteNetwork return networkName, createAndDeleteNetwork
} }
var sanitizeNetworkAliasRegex = regexp.MustCompile("[^A-Z0-9-]") var sanitizeNetworkAliasRegex = regexp.MustCompile("[^a-z0-9-]")
func sanitizeNetworkAlias(ctx context.Context, original string) string { func sanitizeNetworkAlias(ctx context.Context, original string) string {
sanitized := sanitizeNetworkAliasRegex.ReplaceAllString(strings.ToUpper(original), "_") sanitized := sanitizeNetworkAliasRegex.ReplaceAllString(strings.ToLower(original), "_")
if sanitized != original { if sanitized != original {
logger := common.Logger(ctx) logger := common.Logger(ctx)
logger.Infof("The network alias is %s (sanitized version of %s)", original, sanitized) logger.Infof("The network alias is %s (sanitized version of %s)", sanitized, original)
} }
return sanitized return sanitized
} }

View file

@ -712,10 +712,10 @@ func Test_createSimpleContainerName(t *testing.T) {
} }
func TestSanitizeNetworkAlias(t *testing.T) { func TestSanitizeNetworkAlias(t *testing.T) {
same := "SAME" same := "same"
assert.Equal(t, same, sanitizeNetworkAlias(context.Background(), same)) assert.Equal(t, same, sanitizeNetworkAlias(context.Background(), same))
original := "OR.IGIN'A-L" original := "or.igin'A-L"
sanitized := "OR_IGIN_A-L" sanitized := "or_igin_a-l"
assert.Equal(t, sanitized, sanitizeNetworkAlias(context.Background(), original)) assert.Equal(t, sanitized, sanitizeNetworkAlias(context.Background(), original))
} }