diff --git a/src/properties.go b/src/properties.go index 03aaf7c1..56308f13 100644 --- a/src/properties.go +++ b/src/properties.go @@ -121,12 +121,17 @@ func (p *properties) getInt(property Property, defaultValue int) int { return defaultValue } - intValue, ok := val.(int) + if intValue, ok := val.(int); ok { + return intValue + } + + // json parses a float + intValue, ok := val.(float64) if !ok { return defaultValue } - return intValue + return int(intValue) } func (p *properties) getKeyValueMap(property Property, defaultValue map[string]string) map[string]string { diff --git a/src/segment_git.go b/src/segment_git.go index 37540a67..4bd8463e 100644 --- a/src/segment_git.go +++ b/src/segment_git.go @@ -342,7 +342,7 @@ func (g *git) getGitHEADContext(ref string) string { func (g *git) truncateBranch(branch string) string { maxLength := g.props.getInt(BranchMaxLength, 0) - if maxLength == 0 { + if maxLength == 0 || len(branch) < maxLength { return branch } return branch[0:maxLength] diff --git a/src/segment_git_test.go b/src/segment_git_test.go index 857125ed..d622ca8a 100644 --- a/src/segment_git_test.go +++ b/src/segment_git_test.go @@ -778,9 +778,10 @@ func TestTruncateBranch(t *testing.T) { MaxLength interface{} }{ {Case: "No limit", Expected: "all-your-base-are-belong-to-us", Branch: "all-your-base-are-belong-to-us"}, - {Case: "No limit - larger", Expected: "all-your-base", Branch: "all-your-base-are-belong-to-us", MaxLength: 13}, - {Case: "No limit - smaller", Expected: "all-your-base", Branch: "all-your-base", MaxLength: 13}, + {Case: "No limit - larger", Expected: "all-your-base", Branch: "all-your-base-are-belong-to-us", MaxLength: 13.0}, + {Case: "No limit - smaller", Expected: "all-your-base", Branch: "all-your-base", MaxLength: 13.0}, {Case: "Invalid setting", Expected: "all-your-base", Branch: "all-your-base", MaxLength: "burp"}, + {Case: "Lower than limit", Expected: "all-your-base", Branch: "all-your-base", MaxLength: 20.0}, } for _, tc := range cases {