I am trying to use "repoze.bitblt" and could not make it work when my HTML pages use absolute URLs _without_ FQDN, like "/pics/23". For example, the following tag:

    <img src="/pics/23" ...

is transformed into:

    <img src="pics/bitblt-.../23" ...

Note that the leading slash has disappeared. Of course, the image may not be found.

This issue comes from these lines of code in "transform.rewrite_image_tags()":

    parts = path.split('/')
    parts.insert(-1, 'bitblt-%sx%s-%s' % (width, height, signature))
    path = '/'.join(filter(None, parts))

The first "split()" returns a list whose first item is the empty string. Consequentially, the call to "filter()" removes it and we end up swallowing the leading slash in the transformed path.

This seems a pretty obvious bug to me, so I am willing to suppose that it is actually some kind of feature. ;) Is it? Or perhaps nobody noticed because everyone uses full URLs with an FQDN. If the behaviour is however not intended, I have attached a patch that contains a very simple fix and an additional test. I just remove the call to "filter()", but it may not be the best solution: this call was surely here for a good reason, but I do not know why.


N.B.: perhaps I should have reported this in the the issue tracker. I'll be glad to do, should it be the case.

Damien Baty
Index: repoze/bitblt/transform.py
--- repoze/bitblt/transform.py  (révision 5222)
+++ repoze/bitblt/transform.py  (copie de travail)
@@ -35,7 +35,7 @@
             parts = path.split('/')
             parts.insert(-1, 'bitblt-%sx%s-%s' % (width, height, signature))
-            path = '/'.join(filter(None, parts))
+            path = '/'.join(parts)
             img.attrib['src'] = urlparse.urlunparse(
                 (scheme, netloc, path, params, query, fragment))
Index: repoze/bitblt/tests.py
--- repoze/bitblt/tests.py      (révision 5222)
+++ repoze/bitblt/tests.py      (copie de travail)
@@ -87,6 +87,7 @@
             <img src="foo.png" width="640" height="480" />
+            <img src="/foo.png" width="640" height="480" />
             <img src="http://host/bar.png"; width="640" height="480" />
             <img src="http://host/path/hat.png"; width="640" height="480" />
             <img src="blubb.png" />
@@ -113,6 +114,7 @@
         directive = "bitblt-%sx%s-%s" % (width, height, signature)
         body = "".join(result)
         self.failUnless("%s/foo.png" % directive in body)
+        self.failUnless("/%s/foo.png" % directive in body)
         self.failUnless("http://host/%s/bar.png"; % directive in body)
         self.failUnless("http://host/path/%s/hat.png"; % directive in body)
         self.failUnless('<img src="blubb.png">' in body)
@@ -122,7 +124,7 @@
         self.failUnless("%s/blah.png" % directive in body)
         self.assertEqual(response, [
             '200 OK', [('Content-Type', 'text/html; charset=UTF-8'),
-                       ('Content-Length', '478')]])
+                       ('Content-Length', '579')]])
     def test_rewrite_html_limited_to_application_url(self):
         body = '''\
Repoze-dev mailing list

Reply via email to