diff --git a/src/segments/node.go b/src/segments/node.go index 3ebb1c51..c4e5b728 100644 --- a/src/segments/node.go +++ b/src/segments/node.go @@ -76,7 +76,8 @@ func (n *Node) matchesVersionFile() (string, bool) { n.language.version.Patch, ) - version := strings.TrimPrefix(fileVersion, "v") + version := strings.TrimSpace(fileVersion) + version = strings.TrimPrefix(version, "v") return version, regex.MatchString(re, fileVersion) } diff --git a/src/segments/node_test.go b/src/segments/node_test.go index ca4d14a2..997fc5fb 100644 --- a/src/segments/node_test.go +++ b/src/segments/node_test.go @@ -24,6 +24,7 @@ func TestNodeMatchesVersionFile(t *testing.T) { }{ {Case: "no file context", Expected: true, RCVersion: ""}, {Case: "version match", Expected: true, ExpectedVersion: "1.2.3", RCVersion: "1.2.3"}, + {Case: "version match with newline", Expected: true, ExpectedVersion: "1.2.3", RCVersion: "1.2.3\n"}, {Case: "version mismatch", Expected: false, ExpectedVersion: "3.2.1", RCVersion: "3.2.1"}, {Case: "version match in other format", Expected: true, ExpectedVersion: "1.2.3", RCVersion: "v1.2.3"}, {Case: "version match without patch", Expected: true, ExpectedVersion: "1.2", RCVersion: "1.2"},