mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-20 14:48:43 +05:00
Updated RSRParser constant handling
This commit is contained in:
@@ -187,7 +187,6 @@ const (
|
||||
FIELDS_SEP = ","
|
||||
InInFieldSep = ":"
|
||||
STATIC_HDRVAL_SEP = "::"
|
||||
REGEXP_PREFIX = "~"
|
||||
FILTER_VAL_START = "("
|
||||
FILTER_VAL_END = ")"
|
||||
JSON = "json"
|
||||
|
||||
@@ -46,7 +46,8 @@ type NavigableMapper interface {
|
||||
|
||||
// DPDynamicInterface returns the value of the field if the path is dynamic
|
||||
func DPDynamicInterface(dnVal string, dP DataProvider) (interface{}, error) {
|
||||
if strings.HasPrefix(dnVal, DynamicDataPrefix) {
|
||||
if strings.HasPrefix(dnVal, DynamicDataPrefix) &&
|
||||
dnVal != DynamicDataPrefix {
|
||||
dnVal = strings.TrimPrefix(dnVal, DynamicDataPrefix)
|
||||
return dP.FieldAsInterface(strings.Split(dnVal, NestingSep))
|
||||
}
|
||||
@@ -55,7 +56,8 @@ func DPDynamicInterface(dnVal string, dP DataProvider) (interface{}, error) {
|
||||
|
||||
// DPDynamicString returns the string value of the field if the path is dynamic
|
||||
func DPDynamicString(dnVal string, dP DataProvider) (string, error) {
|
||||
if strings.HasPrefix(dnVal, DynamicDataPrefix) {
|
||||
if strings.HasPrefix(dnVal, DynamicDataPrefix) &&
|
||||
dnVal != DynamicDataPrefix {
|
||||
dnVal = strings.TrimPrefix(dnVal, DynamicDataPrefix)
|
||||
return dP.FieldAsString(strings.Split(dnVal, NestingSep))
|
||||
}
|
||||
|
||||
@@ -30,6 +30,9 @@ import (
|
||||
// StringToInterface will parse string into supported types
|
||||
// if no other conversion possible, original string will be returned
|
||||
func StringToInterface(s string) interface{} {
|
||||
if s == EmptyString {
|
||||
return s
|
||||
}
|
||||
// int64
|
||||
if i, err := strconv.ParseInt(s, 10, 64); err == nil {
|
||||
return i
|
||||
|
||||
@@ -231,6 +231,9 @@ func TestStringToInterface(t *testing.T) {
|
||||
if res := StringToInterface("1"); res != int64(1) {
|
||||
t.Error("not parsing int")
|
||||
}
|
||||
if res := StringToInterface(""); res != "" {
|
||||
t.Error("not parsing string")
|
||||
}
|
||||
if res := StringToInterface("true"); res != true {
|
||||
t.Error("not parsing bool")
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ func NewRSRField(fldStr string) (fld *RSRField, err error) {
|
||||
rsrField.filters = filters
|
||||
return rsrField, nil
|
||||
}
|
||||
if !strings.HasPrefix(fldStr, REGEXP_PREFIX) {
|
||||
if !strings.HasPrefix(fldStr, DynamicDataPrefix) {
|
||||
rsrField.Id = fldStr
|
||||
rsrField.filters = filters
|
||||
return rsrField, nil
|
||||
@@ -210,7 +210,7 @@ func NewRSRFilter(fltrVal string) (rsrFltr *RSRFilter, err error) {
|
||||
}
|
||||
}
|
||||
rsrFltr.filterRule = fltrVal
|
||||
if fltrVal[:1] == REGEXP_PREFIX {
|
||||
if fltrVal[:1] == DynamicDataPrefix {
|
||||
if rsrFltr.fltrRgxp, err = regexp.Compile(fltrVal[1:]); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -242,7 +242,7 @@ func (rsrFltr *RSRFilter) Pass(val string) bool {
|
||||
if rsrFltr.filterRule == "" {
|
||||
return !rsrFltr.negative
|
||||
}
|
||||
if rsrFltr.filterRule[:1] == REGEXP_PREFIX {
|
||||
if rsrFltr.filterRule[:1] == DynamicDataPrefix {
|
||||
return rsrFltr.fltrRgxp.MatchString(val) != rsrFltr.negative
|
||||
}
|
||||
if rsrFltr.filterRule == "^$" { // Special case to test empty value
|
||||
|
||||
Reference in New Issue
Block a user