Browse Source

escape some special string to avoid the frontend crash and change the default http code to 400 in MindInsightException

tags/v1.0.0
ougongchang 5 years ago
parent
commit
fe6f548dd2
3 changed files with 17 additions and 2 deletions
  1. +8
    -0
      mindinsight/datavisual/data_transform/graph/graph.py
  2. +7
    -0
      mindinsight/datavisual/data_transform/graph/msgraph.py
  3. +2
    -2
      mindinsight/utils/exceptions.py

+ 8
- 0
mindinsight/datavisual/data_transform/graph/graph.py View File

@@ -28,6 +28,14 @@ from .node import NodeTypeEnum
from .node import Node


def escape_html(string):
"""Escape some html special string to avoid the frontend crash."""
string = string.replace('<', '&lt;')
string = string.replace('>', '&gt;')
string = string.replace('"', '&quot;')
return string


class EdgeTypeEnum(Enum):
"""Node edge type enum."""
CONTROL = 'control'


+ 7
- 0
mindinsight/datavisual/data_transform/graph/msgraph.py View File

@@ -20,6 +20,7 @@ from .node import Node
from .node import NodeTypeEnum
from .graph import Graph
from .graph import EdgeTypeEnum
from .graph import escape_html


class MSGraph(Graph):
@@ -63,6 +64,12 @@ class MSGraph(Graph):
base_name=f'{node_proto.op_type}{node_proto.name}')
else:
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.full_name = node_proto.full_name
node.type = node_proto.op_type


+ 2
- 2
mindinsight/utils/exceptions.py View File

@@ -32,14 +32,14 @@ class MindInsightException(Exception):
LEVEL = 0
SYSID = 42

def __init__(self, error, message, http_code=500):
def __init__(self, error, message, http_code=400):
"""
Initialization of MindInsightException.

Args:
error (Enum): Error value for specified case.
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):
message = ' '.join(message.split())


Loading…
Cancel
Save