diff --git a/apier/v1/cdre.go b/apier/v1/cdre.go index 63e5fe101..2591c0503 100644 --- a/apier/v1/cdre.go +++ b/apier/v1/cdre.go @@ -29,6 +29,7 @@ import ( "strconv" "strings" "time" + "unicode/utf8" "github.com/cgrates/cgrates/cdre" "github.com/cgrates/cgrates/config" @@ -117,8 +118,11 @@ func (self *ApierV1) ExportCdrsToFile(attr utils.AttrExpFileCdrs, reply *utils.E return fmt.Errorf("%s:%s", utils.ERR_MANDATORY_IE_MISSING, "CdrFormat") } fieldSep := exportTemplate.FieldSeparator - if attr.FieldSeparator != nil { - fieldSep = *attr.FieldSeparator + if attr.FieldSeparator != nil && len(*attr.FieldSeparator) != 0 { + fieldSep, _ = utf8.DecodeRuneInString(*attr.FieldSeparator) + if fieldSep == utf8.RuneError { + return fmt.Errorf("%s:FieldSeparator:%s", utils.ERR_SERVER_ERROR, "Invalid") + } } exportDir := exportTemplate.ExportDir if attr.ExportDir != nil && len(*attr.ExportDir) != 0 { diff --git a/utils/apitpdata.go b/utils/apitpdata.go index d58f80324..2c7eec007 100644 --- a/utils/apitpdata.go +++ b/utils/apitpdata.go @@ -517,7 +517,7 @@ type CachedItemAge struct { type AttrExpFileCdrs struct { CdrFormat *string // Cdr output file format - FieldSeparator *rune // Separator used between fields + FieldSeparator *string // Separator used between fields ExportId *string // Optional exportid ExportDir *string // If provided it overwrites the configured export directory ExportFileName *string // If provided the output filename will be set to this diff --git a/utils/storedcdr_test.go b/utils/storedcdr_test.go index 9bf45c31a..d8f022747 100644 --- a/utils/storedcdr_test.go +++ b/utils/storedcdr_test.go @@ -232,6 +232,14 @@ func TestFormatUsage(t *testing.T) { if cdr.FormatUsage("default") != "1640113" { t.Error("Wrong usage format: ", cdr.FormatUsage("default")) } + cdr = StoredCdr{Usage: time.Duration(2) * time.Millisecond} + if cdr.FormatUsage("default") != "0.002" { + t.Error("Wrong usage format: ", cdr.FormatUsage("default")) + } + cdr = StoredCdr{Usage: time.Duration(1002) * time.Millisecond} + if cdr.FormatUsage("default") != "1.002" { + t.Error("Wrong usage format: ", cdr.FormatUsage("default")) + } } func TestStoredCdrAsHttpForm(t *testing.T) { diff --git a/utils/utils_test.go b/utils/utils_test.go index c223cefe6..b6e436809 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -389,6 +389,20 @@ func TestParseDurationWithSecs(t *testing.T) { } else if parsed != durExpected { t.Error("Parsed different than expected") } + durStr = "0.002" + durExpected = time.Duration(2) * time.Millisecond + if parsed, err := ParseDurationWithSecs(durStr); err != nil { + t.Error(err) + } else if parsed != durExpected { + t.Error("Parsed different than expected") + } + durStr = "1.002" + durExpected = time.Duration(1002) * time.Millisecond + if parsed, err := ParseDurationWithSecs(durStr); err != nil { + t.Error(err) + } else if parsed != durExpected { + t.Error("Parsed different than expected") + } } func TestMinDuration(t *testing.T) {