Merge: nitdoc: escape text in generated dot files
authorJean Privat <jean@pryen.org>
Mon, 10 Nov 2014 23:33:12 +0000 (18:33 -0500)
committerJean Privat <jean@pryen.org>
Mon, 10 Nov 2014 23:33:12 +0000 (18:33 -0500)
Unescaping names in dot files generated by nitdoc seems causes the recent failures on jenkins.

The bug was present since the new nitdoc but expressed by #883 that exposes the name of the project in the dot-file:
* On Jenkins, multiple workspace are identified with a @. eq. `workspace@2`
* The name of a Nit project is the name of the directory
* Therefore  the `dot` command aborted when an identifier with @ was found, thus did not produce a map file.
* Therefore nitdoc aborted on the opening of the map file (to include in the HTML)

Retated to #891

Pull-Request: #894
Reviewed-by: Alexis Laferrière <alexis.laf@xymus.net>

1  2 
src/doc/doc_pages.nit

diff --combined src/doc/doc_pages.nit
@@@ -117,9 -117,9 +117,9 @@@ class Nitdo
                end
                # copy shared files
                if ctx.opt_shareurl.value == null then
 -                      sys.system("cp -r {sharedir.to_s}/* {output_dir.to_s}/")
 +                      sys.system("cp -r -- {sharedir.to_s.escape_to_sh}/* {output_dir.to_s.escape_to_sh}/")
                else
 -                      sys.system("cp -r {sharedir.to_s}/resources/ {output_dir.to_s}/resources/")
 +                      sys.system("cp -r -- {sharedir.to_s.escape_to_sh}/resources/ {output_dir.to_s.escape_to_sh}/resources/")
                end
  
        end
@@@ -314,13 -314,11 +314,13 @@@ abstract class NitdocPag
        fun tpl_graph(dot: Buffer, name: String, title: nullable String): nullable TplArticle do
                if ctx.opt_nodot.value then return null
                var output_dir = ctx.output_dir
 -              var file = new OFStream.open("{output_dir}/{name}.dot")
 +              var path = output_dir / name
 +              var path_sh = path.escape_to_sh
 +              var file = new OFStream.open("{path}.dot")
                file.write(dot)
                file.close
 -              sys.system("\{ test -f {output_dir}/{name}.png && test -f {output_dir}/{name}.s.dot && diff {output_dir}/{name}.dot {output_dir}/{name}.s.dot >/dev/null 2>&1 ; \} || \{ cp {output_dir}/{name}.dot {output_dir}/{name}.s.dot && dot -Tpng -o{output_dir}/{name}.png -Tcmapx -o{output_dir}/{name}.map {output_dir}/{name}.s.dot ; \}")
 -              var fmap = new IFStream.open("{output_dir}/{name}.map")
 +              sys.system("\{ test -f {path_sh}.png && test -f {path_sh}.s.dot && diff -- {path_sh}.dot {path_sh}.s.dot >/dev/null 2>&1 ; \} || \{ cp -- {path_sh}.dot {path_sh}.s.dot && dot -Tpng -o{path_sh}.png -Tcmapx -o{path_sh}.map {path_sh}.s.dot ; \}")
 +              var fmap = new IFStream.open("{path}.map")
                var map = fmap.read_all
                fmap.close
  
                var alt = ""
                if title != null then
                        article.title = title
 -                      alt = "alt='{title}'"
 +                      alt = "alt='{title.html_escape}'"
                end
                article.css_classes.add "text-center"
                var content = new Template
 -              content.add "<img src='{name}.png' usemap='#{name}' style='margin:auto' {alt}/>"
 +              var name_html = name.html_escape
 +              content.add "<img src='{name_html}.png' usemap='#{name_html}' style='margin:auto' {alt}/>"
                content.add map
                article.content = content
                return article
@@@ -997,15 -994,15 +997,15 @@@ class NitdocModul
                # build graph
                var op = new RopeBuffer
                var name = "dep_module_{mmodule.nitdoc_id}"
-               op.append("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
+               op.append("digraph \"{name.escape_to_dot}\" \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
                for mmodule in poset do
                        if mmodule == self.mmodule then
-                               op.append("\"{mmodule.name}\"[shape=box,margin=0.03];\n")
+                               op.append("\"{mmodule.name.escape_to_dot}\"[shape=box,margin=0.03];\n")
                        else
-                               op.append("\"{mmodule.name}\"[URL=\"{mmodule.nitdoc_url}\"];\n")
+                               op.append("\"{mmodule.name.escape_to_dot}\"[URL=\"{mmodule.nitdoc_url.escape_to_dot}\"];\n")
                        end
                        for omodule in poset[mmodule].direct_greaters do
-                               op.append("\"{mmodule.name}\"->\"{omodule.name}\";\n")
+                               op.append("\"{mmodule.name.escape_to_dot}\"->\"{omodule.name.escape_to_dot}\";\n")
                        end
                end
                op.append("\}\n")
@@@ -1378,7 -1375,7 +1378,7 @@@ class NitdocClas
  
                var op = new RopeBuffer
                var name = "dep_class_{mclass.nitdoc_id}"
-               op.append("digraph {name} \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
+               op.append("digraph \"{name.escape_to_dot}\" \{ rankdir=BT; node[shape=none,margin=0,width=0,height=0,fontsize=10]; edge[dir=none,color=gray]; ranksep=0.2; nodesep=0.1;\n")
                var classes = poset.to_a
                var todo = new Array[MClass]
                var done = new HashSet[MClass]
                        if done.has(c) then continue
                        done.add c
                        if c == mclass then
-                               op.append("\"{c.name}\"[shape=box,margin=0.03];\n")
+                               op.append("\"{c.name.escape_to_dot}\"[shape=box,margin=0.03];\n")
                        else
-                               op.append("\"{c.name}\"[URL=\"{c.nitdoc_url}\"];\n")
+                               op.append("\"{c.name.escape_to_dot}\"[URL=\"{c.nitdoc_url.escape_to_dot}\"];\n")
                        end
                        var smallers = poset[c].direct_smallers
                        if smallers.length < 10 then
                                for c2 in smallers do
-                                       op.append("\"{c2.name}\"->\"{c.name}\";\n")
+                                       op.append("\"{c2.name.escape_to_dot}\"->\"{c.name.escape_to_dot}\";\n")
                                end
                                todo.add_all smallers
                        else
-                               op.append("\"...\"->\"{c.name}\";\n")
+                               op.append("\"...\"->\"{c.name.escape_to_dot}\";\n")
                        end
                end
                op.append("\}\n")