Skip to content

Commit e1e0cad

Browse files
committed
ref(validation): do float validation in the regex for CPU shares
CI rarely (if ever) reached the float loop
1 parent 3c6ea6c commit e1e0cad

1 file changed

Lines changed: 2 additions & 10 deletions

File tree

rootfs/api/serializers.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# https://docs-v2.readthedocs.io/en/latest/using-workflow/process-types-and-the-procfile/#declaring-process-types
1616
PROCTYPE_MATCH = re.compile(r'^(?P<type>[a-z0-9]+)$')
1717
MEMLIMIT_MATCH = re.compile(r'^(?P<mem>[0-9]+(MB|KB|GB|[BKMG]))$', re.IGNORECASE)
18-
CPUSHARE_MATCH = re.compile(r'^(?P<cpu>[0-9.]+[m]{0,1})$')
18+
CPUSHARE_MATCH = re.compile(r'^(?P<cpu>[-+]?[0-9]*\.?[0-9]+[m]{0,1})$')
1919
TAGVAL_MATCH = re.compile(r'^(?:[a-zA-Z\d][-\.\w]{0,61})?[a-zA-Z\d]$')
2020
CONFIGKEY_MATCH = re.compile(r'^[a-z_]+[a-z0-9_]*$', re.IGNORECASE)
2121

@@ -167,15 +167,6 @@ def validate_cpu(self, data):
167167
if not shares:
168168
raise serializers.ValidationError("CPU shares must be a numeric value")
169169

170-
for share in shares.groupdict().values():
171-
try:
172-
if share[-1] == "m":
173-
float(share[:-1])
174-
else:
175-
float(share)
176-
except ValueError:
177-
raise serializers.ValidationError("CPU units must be a numeric value")
178-
179170
return data
180171

181172
def validate_tags(self, data):
@@ -194,6 +185,7 @@ def validate_tags(self, data):
194185
if len(prefix) > 253:
195186
raise serializers.ValidationError(
196187
"Tag key prefixes must 253 characters or less.")
188+
197189
for part in prefix.split('/'):
198190
if not re.match(TAGVAL_MATCH, part):
199191
raise serializers.ValidationError(

0 commit comments

Comments
 (0)