| @@ -28,6 +28,14 @@ from .node import NodeTypeEnum | |||||
| from .node import Node | from .node import Node | ||||
| def escape_html(string): | |||||
| """Escape some html special string to avoid the frontend crash.""" | |||||
| string = string.replace('<', '<') | |||||
| string = string.replace('>', '>') | |||||
| string = string.replace('"', '"') | |||||
| return string | |||||
| class EdgeTypeEnum(Enum): | class EdgeTypeEnum(Enum): | ||||
| """Node edge type enum.""" | """Node edge type enum.""" | ||||
| CONTROL = 'control' | CONTROL = 'control' | ||||
| @@ -20,6 +20,7 @@ from .node import Node | |||||
| from .node import NodeTypeEnum | from .node import NodeTypeEnum | ||||
| from .graph import Graph | from .graph import Graph | ||||
| from .graph import EdgeTypeEnum | from .graph import EdgeTypeEnum | ||||
| from .graph import escape_html | |||||
| class MSGraph(Graph): | class MSGraph(Graph): | ||||
| @@ -63,6 +64,12 @@ class MSGraph(Graph): | |||||
| base_name=f'{node_proto.op_type}{node_proto.name}') | base_name=f'{node_proto.op_type}{node_proto.name}') | ||||
| else: | else: | ||||
| node_name = node_proto.full_name | node_name = node_proto.full_name | ||||
| # Because the Graphviz plug-in that the UI USES can't handle these special characters, | |||||
| # the special characters are HTML escaped to avoid UI crash. | |||||
| # Doing this on the backend prevents the frontend from doing it every time. | |||||
| node_name = escape_html(node_name) | |||||
| node = Node(name=node_name, node_id=node_proto.name) | node = Node(name=node_name, node_id=node_proto.name) | ||||
| node.full_name = node_proto.full_name | node.full_name = node_proto.full_name | ||||
| node.type = node_proto.op_type | node.type = node_proto.op_type | ||||
| @@ -32,14 +32,14 @@ class MindInsightException(Exception): | |||||
| LEVEL = 0 | LEVEL = 0 | ||||
| SYSID = 42 | SYSID = 42 | ||||
| def __init__(self, error, message, http_code=500): | |||||
| def __init__(self, error, message, http_code=400): | |||||
| """ | """ | ||||
| Initialization of MindInsightException. | Initialization of MindInsightException. | ||||
| Args: | Args: | ||||
| error (Enum): Error value for specified case. | error (Enum): Error value for specified case. | ||||
| message (str): Description for exception. | message (str): Description for exception. | ||||
| http_code (int): Http code for exception. Default is 500. | |||||
| http_code (int): Http code for exception. Default is 400. | |||||
| """ | """ | ||||
| if isinstance(message, str): | if isinstance(message, str): | ||||
| message = ' '.join(message.split()) | message = ' '.join(message.split()) | ||||