styles.css path is wrong for plugins on windows

Bug #643503 reported by Matt Gibson
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mahara
Fix Released
Low
Melissa Draper

Bug Description

Using Mahara 1.2.6 on Windows XP and MySQL. Debugging using Firebug

The paths returned by $THEME->get_url() include use of DIRECTORY_SEPARATOR in the middle of a URL, which doesn't work.

The line caling it is 1029 of /artefact/form/elements/filebrowser.php:

        $pluginsheets = $THEME->get_url('style/style.css', true, 'artefact/file');

And the function causing the problem is get_path() on line 697 of /ib/web.php, which can be fixed by altering line 699 to this:

        $plugindirectory = ($plugindirectory && substr($plugindirectory, -1) != '/') ? $plugindirectory . '/' : $plugindirectory;

Original line 699:

        $plugindirectory = ($plugindirectory && substr($plugindirectory, -1) != DIRECTORY_SEPARATOR) ? $plugindirectory . DIRECTORY_SEPARATOR : $plugindirectory;

Revision history for this message
Andrew Nicols (dobedobedoh) wrote :

Correct file is /artefact/file/form/elements/filebrowser.php

Revision history for this message
Andrew Nicols (dobedobedoh) wrote :

Matt,

Can you provide an example URL which demonstrates this issue.
E.g. going to /index.php when logged in causes the site_logo.png to not be displayed because of this issue.
In my installation, DIRECTORY_SEPARATOR is set to '/' so this test does work.

Andrew

Revision history for this message
Andrew Nicols (dobedobedoh) wrote :

DIRECTORY_SEPARATOR is a predefined constant - http://www.php.net/manual/en/reserved.constants.php
Not sure what it's defined as under Windows XP.

Matt - what version of php are you running?

Revision history for this message
Matt Gibson (matt-inaura) wrote :

Hi Andrew,

I'm running PHP 5.3.1 and on Windows, the DIRECTORY_SEPARATOR is a backslash, leading to URLs like this within the HTML markup:

http://maharapod.localhost/artefact/file\theme/default/static/style/style.css

which don't resolve, e.g. when you visit http://mahara.localhost/artefact/file/index.php where Firebug shows that the above url hasn't resolved to a file, leaving the page without some of its styling.

Revision history for this message
Andrew Nicols (dobedobedoh) wrote :

I've not got a Windows VM running with php at present to fully verify or test patches against, but I see how this could well be the case.

_get_path is used by both get_path and get_url.
I believe php under windows will correctly handle use of forward slashes (/) in a path so this shouldn't cause issues for windows paths.

Since DIRECTORY_SEPARATOR expands to / on linux and I think to both \ and / on windows, it probably does make sense to just replace DIRECTORY_SEPARATOR with / in this case -- any plugin using a trailing backslash (\) as a directory separator in the plugindirectory would only work under Windows and not Linux anyway. It's only get_path that could be adversely affected by this change and only under windows.

I'll leave this to someone with a Windows dev environment to hand unless I get a chance to get one up and running today.

Changed in mahara:
status: New → Triaged
importance: Undecided → Medium
Revision history for this message
François Marier (fmarier) wrote :

We should grep the codebase for DIRECTORY_SEPARATOR and look at stripping them out.

Perhaps updating the developer documentation would be good as well (making a note that we should just always use POSIX paths).

Changed in mahara:
milestone: none → 1.4.0
Changed in mahara:
status: Triaged → Confirmed
Revision history for this message
François Marier (fmarier) wrote :

Let's replace the DIRECTORY_SEPARATOR in Mahara with forward slashes.

Ideally we should also suggest the same thing to Dwoo's upstream and/or submit patches.

Changed in mahara:
importance: Medium → Low
tags: added: bite-sized windows
Melissa Draper (melissa)
Changed in mahara:
assignee: nobody → Melissa Draper (melissa)
Melissa Draper (melissa)
Changed in mahara:
status: Confirmed → In Progress
Melissa Draper (melissa)
Changed in mahara:
status: In Progress → Fix Committed
Changed in mahara:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.