QuoteCronExpressions ensures cron expressions in schedule sections are properly quoted. The YAML library may drop quotes from cron expressions like "0 14 * * 1-5" which causes validation errors since they start with numbers but contain spaces and special chars.
(yamlContent string)
| 114 | // The YAML library may drop quotes from cron expressions like "0 14 * * 1-5" which |
| 115 | // causes validation errors since they start with numbers but contain spaces and special chars. |
| 116 | func QuoteCronExpressions(yamlContent string) string { |
| 117 | workflowUpdateLog.Print("Quoting cron expressions in YAML content") |
| 118 | |
| 119 | // Replace unquoted cron expressions with quoted versions |
| 120 | return cronPattern.ReplaceAllStringFunc(yamlContent, func(match string) string { |
| 121 | // Extract the cron prefix and value |
| 122 | submatches := cronPattern.FindStringSubmatch(match) |
| 123 | if len(submatches) < 3 { |
| 124 | return match |
| 125 | } |
| 126 | prefix := submatches[1] |
| 127 | cronValue := strings.TrimSpace(submatches[2]) |
| 128 | |
| 129 | // Remove any trailing comments |
| 130 | if idx := strings.Index(cronValue, "#"); idx != -1 { |
| 131 | comment := cronValue[idx:] |
| 132 | cronValue = strings.TrimSpace(cronValue[:idx]) |
| 133 | return prefix + `"` + cronValue + `" ` + comment |
| 134 | } |
| 135 | |
| 136 | return prefix + `"` + cronValue + `"` |
| 137 | }) |
| 138 | } |