diff --git a/internal/db/profile_selector_scan.go b/internal/db/profile_selector_scan.go index f00d475953..35fb285ac4 100644 --- a/internal/db/profile_selector_scan.go +++ b/internal/db/profile_selector_scan.go @@ -15,6 +15,7 @@ package db import ( + "encoding/csv" "fmt" "strings" ) @@ -37,7 +38,11 @@ func (s *ProfileSelector) Scan(value interface{}) error { str = strings.TrimSuffix(str, ")") // Split the string by commas to get the individual field values - parts := strings.Split(str, ",") + cr := csv.NewReader(strings.NewReader(str)) + parts, err := cr.Read() + if err != nil { + return fmt.Errorf("failed to scan SelectorInfo: %v", err) + } // Assign the values to the struct fields if len(parts) != 5 { diff --git a/internal/db/profile_selector_scan_test.go b/internal/db/profile_selector_scan_test.go index 9401997b61..7363d0599a 100644 --- a/internal/db/profile_selector_scan_test.go +++ b/internal/db/profile_selector_scan_test.go @@ -47,6 +47,20 @@ func TestScan(t *testing.T) { Comment: "comment1", }, }, + { + name: "Valid input with commas in the selector", + input: []byte(fmt.Sprintf("(%s,%s,repository,\"repository.properties['github/primary_language'] in ['TypeScript', 'Go']\",\"comment1\")", selectorId, profileId)), + expected: ProfileSelector{ + ID: selectorId, + ProfileID: profileId, + Entity: NullEntities{ + Valid: true, + Entities: EntitiesRepository, + }, + Selector: "repository.properties['github/primary_language'] in ['TypeScript', 'Go']", + Comment: "comment1", + }, + }, } for _, tc := range tc {