@@ -33,55 +33,62 @@ class LogScaleFieldValue(BaseQueryFieldValue):
33
33
34
34
def apply_value (self , value : Union [str , int ]) -> str :
35
35
if isinstance (value , str ) and '"' in value :
36
- value = value .translate (str .maketrans ({'"' : r'\"' }))
36
+ value = re .sub (r'(?<!\\)"' , r'\"' , value )
37
+ if isinstance (value , str ) and '/' in value :
38
+ value = re .sub (r'(?<!\\)/' , r'\/' , value )
37
39
return value
38
40
41
+ def apply_field_name (self , field_name : str ) -> str :
42
+ if not field_name .isalpha ():
43
+ return f'"{ field_name } "'
44
+ return field_name
45
+
39
46
def equal_modifier (self , field : str , value : DEFAULT_VALUE_TYPE ) -> str :
40
47
if isinstance (value , list ):
41
48
return f"({ self .or_token .join (self .equal_modifier (field = field , value = v ) for v in value )} )"
42
- return f'{ field } =" { self .apply_value (value )} " '
49
+ return f'{ self . apply_field_name ( field_name = field ) } =/ { self .apply_value (value )} /i '
43
50
44
51
def less_modifier (self , field : str , value : Union [int , str ]) -> str :
45
- return f'{ field } <"{ self .apply_value (value )} "'
52
+ return f'{ self . apply_field_name ( field_name = field ) } <"{ self .apply_value (value )} "'
46
53
47
54
def less_or_equal_modifier (self , field : str , value : Union [int , str ]) -> str :
48
- return f'{ field } <="{ self .apply_value (value )} "'
55
+ return f'{ self . apply_field_name ( field_name = field ) } <="{ self .apply_value (value )} "'
49
56
50
57
def greater_modifier (self , field : str , value : Union [int , str ]) -> str :
51
- return f'{ field } >"{ self .apply_value (value )} "'
58
+ return f'{ self . apply_field_name ( field_name = field ) } >"{ self .apply_value (value )} "'
52
59
53
60
def greater_or_equal_modifier (self , field : str , value : Union [int , str ]) -> str :
54
- return f'{ field } >="{ self .apply_value (value )} "'
61
+ return f'{ self . apply_field_name ( field_name = field ) } >="{ self .apply_value (value )} "'
55
62
56
63
def not_equal_modifier (self , field : str , value : DEFAULT_VALUE_TYPE ) -> str :
57
64
if isinstance (value , list ):
58
65
return f"({ self .or_token .join ([self .not_equal_modifier (field = field , value = v ) for v in value ])} )"
59
- return f'{ field } !=" { self .apply_value (value )} " '
66
+ return f'{ self . apply_field_name ( field_name = field ) } !=/ { self .apply_value (value )} /i '
60
67
61
68
def contains_modifier (self , field : str , value : DEFAULT_VALUE_TYPE ) -> str :
62
69
if isinstance (value , list ):
63
70
return f"({ self .or_token .join (self .contains_modifier (field = field , value = v ) for v in value )} )"
64
- return f'{ field } ="* { self .apply_value (value )} *" '
71
+ return f'{ self . apply_field_name ( field_name = field ) } =/ { self .apply_value (value )} /i '
65
72
66
73
def endswith_modifier (self , field : str , value : DEFAULT_VALUE_TYPE ) -> str :
67
74
if isinstance (value , list ):
68
75
return f"({ self .or_token .join (self .endswith_modifier (field = field , value = v ) for v in value )} )"
69
- return f'{ field } ="* { self .apply_value (value )} " '
76
+ return f'{ self . apply_field_name ( field_name = field ) } =/ { self .apply_value (value )} $/i '
70
77
71
78
def startswith_modifier (self , field : str , value : DEFAULT_VALUE_TYPE ) -> str :
72
79
if isinstance (value , list ):
73
80
return f"({ self .or_token .join (self .startswith_modifier (field = field , value = v ) for v in value )} )"
74
- return f'{ field } =" { self .apply_value (value )} *" '
81
+ return f'{ self . apply_field_name ( field_name = field ) } =/^ { self .apply_value (value )} /i '
75
82
76
83
def regex_modifier (self , field : str , value : DEFAULT_VALUE_TYPE ) -> str :
77
84
if isinstance (value , list ):
78
85
return f"({ self .or_token .join (self .regex_modifier (field = field , value = v ) for v in value )} )"
79
- return f'{ field } =" /{ self .apply_value (value )} /" '
86
+ return f'{ self . apply_field_name ( field_name = field ) } = /{ self .apply_value (value )} /'
80
87
81
88
def keywords (self , field : str , value : DEFAULT_VALUE_TYPE ) -> str :
82
89
if isinstance (value , list ):
83
90
return f"({ self .or_token .join (self .keywords (field = field , value = v ) for v in value )} )"
84
- return f'" { self .apply_value (value )} " '
91
+ return f'/ { self .apply_value (value )} /i '
85
92
86
93
87
94
class LogScaleQueryRender (BaseQueryRender ):
0 commit comments