Skip to content

Commit

Permalink
fix: Ignore TFM if not found
Browse files Browse the repository at this point in the history
  • Loading branch information
paulomorgado committed Nov 1, 2023
1 parent 1f5d3ea commit c52de54
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/segments/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package segments
import (
"encoding/json"
"encoding/xml"
"errors"
"path/filepath"
"strings"

Expand Down Expand Up @@ -226,11 +225,10 @@ func (n *Project) getDotnetProject(_ ProjectItem) *ProjectData {
// so instead of xml.Unmarshal() we use regex:
tag := "(?P<TAG><.*TargetFramework.*>(?P<TFM>.*)</.*TargetFramework.*>)"
values := regex.FindNamedRegexMatch(tag, content)
if len(values) == 0 {
n.Error = errors.New("cannot extract TFM from " + name + " project file").Error()
return nil
target := ""
if len(values) != 0 {
target = values["TFM"]
}
target := values["TFM"]

return &ProjectData{
Target: target,
Expand Down
4 changes: 2 additions & 2 deletions src/segments/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,8 +343,8 @@ func TestDotnetProject(t *testing.T) {
Case: "invalid or empty contents",
FileName: "Invalid.csproj",
HasFiles: true,
ExpectedEnabled: false,
ExpectedString: "cannot extract TFM from Invalid project file",
ExpectedEnabled: true,
ExpectedString: "Invalid",
},
{
Case: "no files",
Expand Down

0 comments on commit c52de54

Please sign in to comment.