bug in image paths

Found a bug? Tell us!!
Post Reply
SHRIKEE
Regular
Posts: 128
Joined: Tue Feb 21, 2006 2:49 am
Location: Netherlands
Contact:

bug in image paths

Post by SHRIKEE »

Hi all,

Yes the terrible SHRIKEE has something to complain again! :shock:

While working on usergallery plugin mgroeninger found a bug in the paths of s9y. When a file is saved in a subfolder some / become //.

He also made a quick workaround for usergallery to deal with this. Assuming it was fixed. Sadly it was not. When i got the code from him and tested it on my server it apeared that the // caused usergallery to malfunction. Even removing mgroeninger's fix did not solve the problem. So here i am. Crying for a patch.

in short:
when uploading an image to a subfolder using the media library the paths are messed up with // where it should be /
My kingdom For i am king of my heap of trash

Developing code on:
Workstation: Windows 2000 sp4, TSW webcoder 2005
Server: fedora core 4 amd64, apache 2.0.54, php 5.0.4, mysql 4.1.11.
mgroeninger
Regular
Posts: 546
Joined: Mon Dec 20, 2004 11:57 pm
Contact:

Post by mgroeninger »

SHRIKEE, I got your email but I figure working on this here will be easier than trying to co-ordinate a bunch of different emails...

Garvin, sometime in the next few days I will sit down and try to trace this issue... (Or at least write a full bug report of what I am seeing.)

If you know of something that might cause it off the top of your head, I'd love any suggestions...

Essentially, in my two installs (One 0.9.1 and the other 1.0-beta1, running under apache 1.3.33 on windows, php 4.3.11) I am finding serendipity_traversePath will return paths with multiple backslashes for some subfolders below two levels. I don't know which subfolders or why they are a problem yet.

I believe the difference between SHRIKEE's problem and mine probably arise from different methods of adding the files. I used the "Rebuild Thumbs" link in the administrator, and I would bet money SHRIKEE used the standard form to add the images, which happens to use serendipity_traversePath output for the dropdown box. So I believe the problem is just in the relpath output from serendipity_traversePath.

Testing the addition of a picture to the database using the Add media page I receive this output:

Code: Select all

File what-I-would-use.jpg successfully uploaded as C:/serendipitypath/uploads/Alphie//Alphie1//test1/test2/what-I-would-use.jpg
Thumbnail created.
Done.

Note the double slashes between Alphie and Alphie1 and test1... That data is added to the database.

The check I used to test for this in input (in the usergallery plugin) is:

Code: Select all

$getpathtemp = str_replace("//","/",str_replace("..","",$_GET['gallery']));
(obviously this is also testing for dots in the path..)

I think perhaps a patch like (untested patch follows):

Code: Select all

Index: functions_images.inc.php
===================================================================
--- functions_images.inc.php	(revision 993)
+++ functions_images.inc.php	(working copy)
@@ -1619,7 +1619,7 @@
                     $files[] = array(
                         'name'      => $file,
                         'depth'     => $depth,
-                        'relpath'   => ltrim(str_replace('\\', '/', serendipity_dirSlash('end', $dir)) . basename($file) . ($bIsDir ? '/' : ''), '/'),
+                        'relpath'   => str_replace("//","/",ltrim(str_replace('\\', '/', serendipity_dirSlash('end', $dir)) . basename($file) . ($bIsDir ? '/' : ''), '/')),
                         'directory' => $bIsDir
                     );
                 }
would work, but certainly does not address the underlying cause. It also might break installs for anyone who is operating with this type of structure.
SHRIKEE
Regular
Posts: 128
Joined: Tue Feb 21, 2006 2:49 am
Location: Netherlands
Contact:

Post by SHRIKEE »

Uploading files with ftp or similiar and rebuilding the thumbs indeed saves correct paths.
My kingdom For i am king of my heap of trash

Developing code on:
Workstation: Windows 2000 sp4, TSW webcoder 2005
Server: fedora core 4 amd64, apache 2.0.54, php 5.0.4, mysql 4.1.11.
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Post by garvinhicking »

This has been addressed and fixed in Serendipity 1.1 already, where the media manager code has been altered in several places.

Having a "//" path however does NOT matter at all for a webserver, so this should not be any problem there; and code reading from the database could use a "LIKE 'blabla/%' code to fetch images?

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
SHRIKEE
Regular
Posts: 128
Joined: Tue Feb 21, 2006 2:49 am
Location: Netherlands
Contact:

Post by SHRIKEE »

If it was just that simple...
In fact ive tried altering the query to use some thing along these lines

SELECT * FROM {prefix}images WHERE path LIKE '%$dirvariableofwhichiforgotthename%' ORDER BY $order $orderby

but that didnt work :(

*back to guildwars*
My kingdom For i am king of my heap of trash

Developing code on:
Workstation: Windows 2000 sp4, TSW webcoder 2005
Server: fedora core 4 amd64, apache 2.0.54, php 5.0.4, mysql 4.1.11.
SHRIKEE
Regular
Posts: 128
Joined: Tue Feb 21, 2006 2:49 am
Location: Netherlands
Contact:

Post by SHRIKEE »

I just noticed that if there are spaces in a foldername the rebuild thumbs option goes nuts. and wont do anything with the images aswell as not adding them to the database.
My kingdom For i am king of my heap of trash

Developing code on:
Workstation: Windows 2000 sp4, TSW webcoder 2005
Server: fedora core 4 amd64, apache 2.0.54, php 5.0.4, mysql 4.1.11.
Post Reply