Ticket #84 (bug)

Opened 1 year ago

Last modified 1 year ago

Links for items not in the same Folder incorrect

Status: closed (fixed)

Reported by: forsberg Assigned to: fenix
Priority: major Component: qPloneResolveUID
Keywords: Cc:

If I have the following site structure:

/images/ /images/image1

/contentfolder/ /contentfolder/doc1

..linking from doc1 to /images/image1 via UID produces a link on the form <a href="images/image1", lacking the initial /. This does in most cases work due to aquisition, but it leads to ugly URLs - the browser parses it as /contentfolder/images/image1, which will probably lead to bad caching of for example sitewide images.

The following patch (which includes test) fixes the problem:

Index: tests/data.py
===================================================================
--- tests/data.py	(revision 960)
+++ tests/data.py	(working copy)
@@ -6,6 +6,7 @@
       <a href="resolveuid/%s"/>
       <img src="resolveuid/%s"/>
       <img src="resolveuid/%s"/>
+      <a href="resolveuid/%s"/>
       <a href="resolveuid/thisisuidtodeletedobject">
     </div>
   </body>
@@ -15,10 +16,11 @@
   <body>
     <h1>Test page</h1>
     <div>
-      <a href="test1"/>
-      <img src="test1/test2"/>
-      <img src="test1/test2/image_mini"/>
+      <a href="/test1"/>
+      <img src="/test1/test2"/>
+      <img src="/test1/test2/image_mini"/>
+      <a href="/folder2/docintoplevelfolder"/>
       <a href="resolveuid/thisisuidtodeletedobject">
     </div>
   </body>
-</html>"""
\ No newline at end of file
+</html>"""
Index: tests/test_transforms.py
===================================================================
--- tests/test_transforms.py	(revision 960)
+++ tests/test_transforms.py	(working copy)
@@ -54,6 +54,13 @@
         if not 'test1' in self.portal.objectIds():
             self.portal.invokeFactory('Folder', 'test1')
         test1 = getattr(self.portal, 'test1', None)
+        if not "folder2" in self.portal.objectIds():
+            self.portal.invokeFactory('Folder', 'folder2')
+
+        folder2 = getattr(self.portal, "folder2", None)
+        folder2.invokeFactory("Document", "docintoplevelfolder")
+        docintoplevelfolder = getattr(folder2, "docintoplevelfolder")
+
         if test1:
             test1_uid = test1.UID()
             test1.invokeFactory('Document', 'test2')
@@ -61,7 +68,7 @@
             if test2:
                 test2_uid = test2.UID()
         self.assertEqual(self.pt.convert('ruid_to_url',
-                                         orig_text %(test1_uid, test2_uid, test2_uid+'/image_mini'),
+                                         orig_text %(test1_uid, test2_uid, test2_uid+'/image_mini', docintoplevelfolder.UID()),
                                          context = self.portal
                                         ).getData(),
                          result
@@ -77,4 +84,4 @@
     return suite
 
 if __name__ == '__main__':
-    framework()
\ No newline at end of file
+    framework()
Index: transforms/ruid_to_url.py
===================================================================
--- transforms/ruid_to_url.py	(revision 960)
+++ transforms/ruid_to_url.py	(working copy)
@@ -44,7 +44,7 @@
         for uid in unique_ruid:
             obj = rc.lookupObject(uid)
             if obj:
-                ruid_url[uid] = pu.getRelativeUrl(obj)
+                ruid_url[uid] = "/" + pu.getRelativeUrl(obj)
         return ruid_url           
     
     def convert(self, orig, data, **kwargs):
@@ -63,4 +63,4 @@
 
 def register():
     return ruid_to_url()
-    
\ No newline at end of file
+    

Change History

09/17/07 14:52:55: Modified by forsberg

(Plone 2.5.3 on Zope 2.9.8, if it matters)

10/02/07 06:35:51: Modified by chervol

  • status changed from new to assigned.
  • owner changed from fenix to chervol.

10/02/07 06:39:11: Modified by chervol

  • status changed from assigned to new.
  • owner changed from chervol to fenix.

10/09/07 06:55:15: Modified by fenix

  • status changed from new to closed.
  • resolution set to fixed.

fixed in [989] revision!