osimons  committed d3e15ed

[svn r9818] XmlRpcPlugin: Fix for rendering wiki HTML in proper context for correct links and references to relative resources (such as image attachment reference).

Added test for absolute and relative attachment, but test only passes on Trac 0.11 - Trac 0.12 seems to have a bug here...

References #8466

  • Participants
  • Parent commits 28ac2f2

Comments (0)

Files changed (2)

File trunk/tracrpc/tests/
+    def test_getPageHTMLWithImage(self):
+        # Create the wiki page (absolute image reference)
+                        '[[Image(wiki:ImageTest:feed.png, nolink)]]\n', {})
+        # Create attachment
+        image_url = os.path.join(rpc_testenv.trac_src, 'trac',
+                             'htdocs', 'feed.png')
+'ImageTest', 'feed.png', 'test image',
+            xmlrpclib.Binary(open(image_url, 'r').read()))
+        # Check rendering absolute
+        markup_1 ='ImageTest')
+        self.assertEquals('<html><body><p>\n<img src="'
+                '/raw-attachment/wiki/ImageTest/feed.png" alt="test image" '
+                'title="test image" />\n</p>\n</body></html>', markup_1)
+        # Change to relative image reference and check again
+                        '[[Image(feed.png, nolink)]]\n', {})
+        markup_2 ='ImageTest')
+        self.assertEquals(markup_2, markup_1)
 def test_suite():
     return unittest.makeSuite(RpcWikiTestCase)

File trunk/tracrpc/

 from trac.attachment import Attachment
 from trac.core import *
+from trac.mimeview import Context
 from trac.resource import Resource, ResourceNotFound
 from import WikiSystem
 from import WikiPage
-from import wiki_to_html
+from import wiki_to_html, format_to_html
 from tracrpc.api import IXMLRPCHandler, expose_rpc, Binary
 from tracrpc.util import StringIO, to_utimestamp, from_utimestamp
     def getPageHTML(self, req, pagename, version=None):
         """ Return page in rendered HTML, latest version. """
         text = self.getPage(req, pagename, version)
-        html = wiki_to_html(text, self.env, req, absurls=1)
+        resource = Resource('wiki', pagename, version)
+        context = Context.from_request(req, resource, absurls=True)
+        html = format_to_html(self.env, context, text)
         return '<html><body>%s</body></html>' % html
     def getAllPages(self, req):