Skip to content

Commit

Permalink
Tooltips should be html.escaped
Browse files Browse the repository at this point in the history
  • Loading branch information
dsblank committed Aug 10, 2017
1 parent 25adb41 commit bd00dcd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions conx/layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from functools import reduce
import sys
import inspect
import html
import re
import os

Expand Down Expand Up @@ -289,15 +290,16 @@ def tooltip(self):
if key in ["name"]:
continue
retval += "\n %s = %s" % (key, self.params[key])
return retval
return html.escape(retval)

class Layer(_BaseLayer):
"""
The default layer type. Will create either an InputLayer, or DenseLayer,
depending on its context after :any:`Network.connect`.
Arguments:
name: The name of the layer. Must be unique in this network.
name: The name of the layer. Must be unique in this network. Should
not contain special HTML characters.
Examples:
>>> layer = Layer("input", 10)
Expand Down
8 changes: 5 additions & 3 deletions conx/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import signal
import numbers
import base64
import html
import copy
import io
import PIL
Expand All @@ -51,7 +52,8 @@ class Network():
The main class for the conx neural network package.
Arguments:
name: Required. The name of the network.
name: Required. The name of the network. Should not contain special HTML
characters.
sizes: Optional numbers. Defines the sizes of layers of a sequential
network. These will be created, added, and connected automatically.
config: Configuration overrides for the network.
Expand Down Expand Up @@ -1491,7 +1493,7 @@ def build_svg(self, opts={}):
rect_extra = 0
if rect_width < 20:
rect_extra = 10
tooltip = self.describe_connection_to(self[layer_name], out)
tooltip = html.escape(self.describe_connection_to(self[layer_name], out))
svg += arrow_rect.format(**{"tooltip": tooltip,
"rx": min(x2, x1) - rect_extra,
"ry": min(y2, y1) + 2, # bring down
Expand All @@ -1501,7 +1503,7 @@ def build_svg(self, opts={}):
if out.name not in positioning:
continue
# draw an arrow between layers:
tooltip = self.describe_connection_to(self[layer_name], out)
tooltip = html.escape(self.describe_connection_to(self[layer_name], out))
x2 = positioning[out.name]["x"] + positioning[out.name]["width"]/2
y2 = positioning[out.name]["y"] + positioning[out.name]["height"]
svg += arrow_svg.format(
Expand Down

0 comments on commit bd00dcd

Please sign in to comment.