[Piglit] [PATCH] framework/summary/html: Prevent forward slashes in URLs.

jfonseca at vmware.com jfonseca at vmware.com
Thu Jun 12 05:22:12 PDT 2014

From: José Fonseca <jfonseca at vmware.com>

It's fine for URLs to have forward slash directory separators when viewing
the HTML on Windows.  But if one moves the HTML report to a Linux machine
or puts it on a web-server and accesses it from a Linux machine then URLs
with forward slashes become dead.

This change prevents this be replacing \ with /.

(There might be an easier way to achieve this than to have so many
instances of foo.replace('\\', '/').  For example, it might be easier to
do this replacement when loading the results.  On the other hand,
there are several places that use os.path, so it might not solve the
issue completely neither.)
 framework/summary.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/framework/summary.py b/framework/summary.py
index 7e8d480..e5eb156 100644
--- a/framework/summary.py
+++ b/framework/summary.py
@@ -22,6 +22,7 @@
 from __future__ import print_function
 import os
 import os.path as path
+import posixpath
 import itertools
 import shutil
 import collections
@@ -46,6 +47,11 @@ def escape_filename(key):
     return re.sub(r'[<>:"|?*]', '_', key)
+def normalize_href(href):
+    """Force backward slashes in URLs."""
+    return href.replace('\\', '/')
 class HTMLIndex(list):
     Builds HTML output to be passed to the index mako template, which will be
@@ -107,12 +113,13 @@ class HTMLIndex(list):
         self.append({'type': 'other', 'text': '<td />'})
         for each in summary.results:
+            href = posixpath.join(each.name, "index.html")
+            href = normalize_href(href)
             self.append({'type': 'other',
                          'text': '<td class="head"><b>%(name)s</b><br />'
                                  '(<a href="%(href)s">info</a>)'
                                  '</td>' % {'name': each.name,
-                                            'href': path.join(each.name,
-                                                              "index.html")}})
+                                            'href': href}})
         # Add the toplevel 'all' group
@@ -247,7 +254,8 @@ class HTMLIndex(list):
             href = None
             css = text
-            href = path.join(group, href + ".html")
+            href = posixpath.join(group, href + ".html")
+            href = normalize_href(href)
         self.append({'type': 'testResult',
                      'class': css,

More information about the Piglit mailing list