diff --git a/gns3server/controller/node.py b/gns3server/controller/node.py index 298f95e5..1b5882ad 100644 --- a/gns3server/controller/node.py +++ b/gns3server/controller/node.py @@ -239,6 +239,7 @@ class Node: @symbol.setter def symbol(self, val): + if val is None: val = ":/symbols/computer.svg" @@ -252,8 +253,9 @@ class Node: self._symbol = val try: self._width, self._height, filetype = self._project.controller.symbols.get_size(val) - # If symbol is invalid we replace it by default - except (ValueError, OSError): + except (ValueError, OSError) as e: + log.error("Could not write symbol: {}".format(e)) + # If symbol is invalid we replace it by the default self.symbol = ":/symbols/computer.svg" if self._label is None: # Apply to label user style or default diff --git a/gns3server/utils/picture.py b/gns3server/utils/picture.py index 1ec072de..d7c3103b 100644 --- a/gns3server/utils/picture.py +++ b/gns3server/utils/picture.py @@ -103,10 +103,16 @@ def get_size(data, default_width=0, default_height=0): root = tree.getroot() try: - width = _svg_convert_size(root.attrib.get("width", "0")) - height = _svg_convert_size(root.attrib.get("height", "0")) - except IndexError: - raise ValueError("Invalid SVG file") + width_attr = root.attrib.get("width", "0") + height_attr = root.attrib.get("height", "0") + if width_attr.endswith("%") or height_attr.endswith("%"): + # check to viewBox attribute if width or height value is a percentage + _, _, width_attr, height_attr = root.attrib.get("viewBox").split() + else: + width = _svg_convert_size(width_attr) + height = _svg_convert_size(height_attr) + except (AttributeError, IndexError) as e: + raise ValueError("Invalid SVG file: {}".format(e)) return width, height, filetype