Skip to content

Commit d0e3c3e

Browse files
authored
Merge pull request #30 from fishingfly/bugfix/number
fix bug: number need double quotes in annoations or labels
2 parents c2001ae + 7074f8f commit d0e3c3e

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

pkg/template/string_validator.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package template
2+
3+
import (
4+
"strconv"
5+
"strings"
6+
)
7+
8+
type String string
9+
10+
func (s String) IsBool() bool {
11+
return s == "true" || s == "false"
12+
}
13+
14+
func (s String) IsDecimal() bool {
15+
_, err := strconv.Atoi(string(s))
16+
return err == nil
17+
}
18+
19+
func (s String) HasNewLine() bool {
20+
return strings.Contains(string(s), "\n")
21+
}

pkg/template/template.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,10 @@ func (p *Processor) walk(v reflect.Value, nindent int, root config.XPath, sliceI
424424
p.context.setRoleNamespace = true
425425
}
426426
p.logger.V(10).Info("Processing others", "root", root, "s", s)
427-
if s == "true" || s == "false" {
427+
str := String(s)
428+
if str.IsBool() || str.IsDecimal() {
428429
fmt.Fprintf(p.context.out, "\"%s\"\n", v)
429-
} else if strings.Contains(s, "\n") {
430+
} else if str.HasNewLine() {
430431
fmt.Fprintf(p.context.out, "|\n%s\n", indent(s, nindent+1))
431432
} else {
432433
fmt.Fprintln(p.context.out, v)

0 commit comments

Comments
 (0)