From f7f70108bc209f99aeb3c900cfaf06af65b1c86b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Fri, 5 Dec 2014 12:20:35 +0100 Subject: [PATCH] Make sure the printer profile fields are all of the correct type during validation --- src/octoprint/server/api/printer_profiles.py | 52 +++++++++++++++---- .../js/app/viewmodels/printerprofiles.js | 2 +- 2 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/octoprint/server/api/printer_profiles.py b/src/octoprint/server/api/printer_profiles.py index d7b80112..5f04fa7b 100644 --- a/src/octoprint/server/api/printer_profiles.py +++ b/src/octoprint/server/api/printer_profiles.py @@ -111,17 +111,47 @@ def _convert_profile(profile): return converted def _validate_profile(profile): - return "name" in profile \ - and "volume" in profile \ - and "width" in profile["volume"] \ - and "depth" in profile["volume"] \ - and "height" in profile["volume"] \ - and "formFactor" in profile["volume"] \ - and "heatedBed" in profile \ - and "extruder" in profile \ - and "count" in profile["extruder"] \ - and "offsets" in profile["extruder"] \ - and len(profile["extruder"]["offsets"]) == profile["extruder"]["count"] + if not "name" in profile \ + and "volume" in profile \ + and "width" in profile["volume"] \ + and "depth" in profile["volume"] \ + and "height" in profile["volume"] \ + and "formFactor" in profile["volume"] \ + and "heatedBed" in profile \ + and "extruder" in profile \ + and "count" in profile["extruder"] \ + and "offsets" in profile["extruder"] \ + and len(profile["extruder"]["offsets"]) == profile["extruder"]["count"]: + return False + + for dimension in ("width", "depth", "height"): + try: + profile["volume"][dimension] = float(profile["volume"][dimension]) + except: + return False + + if not profile["volume"]["formFactor"] in ("rectangular", "circular"): + return False + + try: + profile["heatedBed"] = bool(profile["heatedBed"]) + except: + return False + + try: + profile["extruder"]["count"] = int(profile["extruder"]["count"]) + except: + return False + + converted_offsets = [] + for offset in profile["extruder"]["offsets"]: + try: + converted_offsets.append((float(offset[0]), float(offset[0]))) + except: + return False + profile["extruder"]["offsets"] = converted_offsets + + return True def _overwrite_profile(profile): if not "id" in profile and not "name" in profile: diff --git a/src/octoprint/static/js/app/viewmodels/printerprofiles.js b/src/octoprint/static/js/app/viewmodels/printerprofiles.js index 7b33d0a9..f6675a4e 100644 --- a/src/octoprint/static/js/app/viewmodels/printerprofiles.js +++ b/src/octoprint/static/js/app/viewmodels/printerprofiles.js @@ -271,7 +271,7 @@ function PrinterProfilesViewModel() { width: self.editorVolumeWidth(), depth: self.editorVolumeDepth(), height: self.editorVolumeHeight(), - type: self.editorVolumeFormFactor() + formFactor: self.editorVolumeFormFactor() }, heatedBed: self.editorHeatedBed(), extruder: {