Browse Source

will ignore the graph if there are some invalid characters

tags/v1.0.0
ougongchang 5 years ago
parent
commit
956535eed2
2 changed files with 12 additions and 11 deletions
  1. +7
    -6
      mindinsight/datavisual/data_transform/graph/graph.py
  2. +5
    -5
      mindinsight/datavisual/data_transform/graph/msgraph.py

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

@@ -28,12 +28,13 @@ 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
def check_invalid_character(string):
"""Check for invalid characters. These characters will cause frontend crash."""
invalid_char = {'>', '<', '"'}
result = set(string).intersection(invalid_char)
if result:
raise ParamValueError(f"There are some invalid characters in graph node, invalid string: {string}, "
f"unexpected characters: {result}")


class EdgeTypeEnum(Enum):


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

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


class MSGraph(Graph):
@@ -65,10 +65,8 @@ class MSGraph(Graph):
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)
# The Graphviz plug-in that the UI USES can't handle these special characters.
check_invalid_character(node_name)

node = Node(name=node_name, node_id=node_proto.name)
node.full_name = node_proto.full_name
@@ -97,6 +95,7 @@ class MSGraph(Graph):
if not parameter.name:
logger.warning("Finding a parameter with an empty name will not save it.")
continue
check_invalid_character(parameter.name)
node = Node(name=parameter.name, node_id=parameter.name)
node.type = NodeTypeEnum.PARAMETER.value
node.output_shape = self._get_shape_by_parse_type_proto(parameter.type)
@@ -124,6 +123,7 @@ class MSGraph(Graph):
if not const.key:
logger.warning("Finding a const with an empty key will not save it.")
continue
check_invalid_character(const.key)
node = Node(name=const.key, node_id=const.key)
node.type = NodeTypeEnum.CONST.value
if const.value.ByteSize() > self.MAX_NODE_ATTRIBUTE_VALUE_BYTES:


Loading…
Cancel
Save