From 28c639e48bd13fba21e11e8f24c27baee19c4954 Mon Sep 17 00:00:00 2001 From: Earl Warren Date: Sat, 26 Jul 2025 11:31:05 +0000 Subject: [PATCH] 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 Co-authored-by: Earl Warren Co-committed-by: Earl Warren --- act/runner/run_context.go | 6 +++--- act/runner/run_context_test.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/act/runner/run_context.go b/act/runner/run_context.go index f8e8782f..2f0cce32 100644 --- a/act/runner/run_context.go +++ b/act/runner/run_context.go @@ -402,13 +402,13 @@ func (rc *RunContext) getNetworkName(_ context.Context) (networkName string, cre 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 { - sanitized := sanitizeNetworkAliasRegex.ReplaceAllString(strings.ToUpper(original), "_") + sanitized := sanitizeNetworkAliasRegex.ReplaceAllString(strings.ToLower(original), "_") if sanitized != original { 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 } diff --git a/act/runner/run_context_test.go b/act/runner/run_context_test.go index 0c2a3c86..8c362b3a 100644 --- a/act/runner/run_context_test.go +++ b/act/runner/run_context_test.go @@ -712,10 +712,10 @@ func Test_createSimpleContainerName(t *testing.T) { } func TestSanitizeNetworkAlias(t *testing.T) { - same := "SAME" + same := "same" assert.Equal(t, same, sanitizeNetworkAlias(context.Background(), same)) - original := "OR.IGIN'A-L" - sanitized := "OR_IGIN_A-L" + original := "or.igin'A-L" + sanitized := "or_igin_a-l" assert.Equal(t, sanitized, sanitizeNetworkAlias(context.Background(), original)) }