@@ -152,16 +152,15 @@ def get_queryset(self):
152
152
company = self .request .user ,
153
153
)
154
154
155
- countries = self .request .query_params .getlist ('country' , [])
156
- country_list = []
157
-
158
- for country_group in countries :
159
- country_list .extend (country_group .split (',' ))
160
-
161
- country_list = [c .strip () for c in country_list if c .strip ()]
162
-
163
- if country_list :
164
- regex_pattern = r'(' + '|' .join (map (re .escape , country_list )) + ')'
155
+ countries = [
156
+ country .strip ()
157
+ for group in self .request .query_params .getlist ('country' , [])
158
+ for country in group .split (',' )
159
+ if country .strip ()
160
+ ]
161
+
162
+ if countries :
163
+ regex_pattern = r'(' + '|' .join (map (re .escape , countries )) + ')'
165
164
queryset = queryset .filter (
166
165
django .db .models .Q (target__country__iregex = regex_pattern )
167
166
| django .db .models .Q (target__country__isnull = True ),
@@ -210,9 +209,17 @@ def _validate_countries(self, errors):
210
209
country_list = []
211
210
212
211
for country_group in countries :
213
- country_list .extend (country_group .split (',' ))
212
+ parts = [part .strip () for part in country_group .split (',' )]
213
+
214
+ if any (part == '' for part in parts ):
215
+ raise rest_framework .exceptions .ValidationError (
216
+ 'Invalid country format.' ,
217
+ )
218
+
219
+ country_list .extend (parts )
214
220
215
221
country_list = [c .strip ().upper () for c in country_list if c .strip ()]
222
+
216
223
invalid_countries = []
217
224
218
225
for code in country_list :
0 commit comments