Bug in file server: invalid trailing in directories on Windows

Bug #644958 reported by Jaakko
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Rocket Web Server
Fix Committed
Undecided
Unassigned

Bug Description

I am using Rocket 1.1.1 (Rocket-src-1.1.1.zip).

Rocket's embedded fileserver (method='fs') adds invalid trailing to files inside subdirectories on Windows.

How to duplicate (either cPython or Jython):
- Run examples\fs.py within a folder that has a subdirectory ('data') and files in it ('data\data1.html')
- Open subdirectory in browser ('http://localhost/data')
- Instead of URL-style slash ('/'), file URLs are errorneously escaped with Windows-style slash ('\').
- For instance: 'http://localhost/data\data1.html' -> should be 'http://localhost/data/data1.html'

This behaviour becomes a problem when HTML files have relative references to files within same directory (for instance data1.css) since Windows-style backslashes are often not interpreted as trailing slashes (browser tries to retrieve 'http://localhost/data1.css' instead of 'http://localhost/data\data1.css')

Jaakko (jaakko-salonen)
description: updated
description: updated
description: updated
Revision history for this message
Jaakko (jaakko-salonen) wrote :

I can confirm now that similar bug exists for directories inside directories

Please find attached a diff to patch this bug (for methods/fs.py).

Revision history for this message
Tim (tdfarrell) wrote :

Jaakko,

Thanks for pointing this out. ATM, I can't duplicate this and I also can't see the diff you attached. Thank you for taking the effort to provide it though. I'm launching 1.2.0 tonight (which doesn't seem to have this problem. Please test it as well.

Revision history for this message
Tim (tdfarrell) wrote :

Clarification, I can't see the diff you attached because launchpad is being dumb.

Revision history for this message
Jaakko (jaakko-salonen) wrote : Re: [Bug 644958] Re: Bug in file server: invalid trailing in directories on Windows

Hi Tim,

I can confirm that this bug still exists in Rocket 1.2.0

How to replicate:
- Run Windows or any system with backslash (\) as directory separator
- Run "python examples\fs.py"
- Open localhost in your browser
- Navigate to any folder with browser, such as to "http://localhost/examples"
- URLs to any files inside this folder are errorneously escaped with a
backslash (\) instead of slash (/).
- For instance: "http://localhost/examples\fs.py" -> should be
"http://localhost/examples/fs.py"

In most situations this is OK, but when an HTML file is loaded then
relative references to other files, such as stylesheets inside the
same folder don't work.

The problem can be traced back to methods/fs.py where URLs are
constructed using os.path.join. When building URLs, urlparse.urljoin
should be used instead (especially lines 115 and 117):

Quick fix would be to replace backslashes with slashes, but a less
hacky solution would be to switch to use urlparse.urljoin instead.

I hope this clarifies the issue!

2010/12/1 Tim <email address hidden>:
> Jaakko,
>
> Thanks for pointing this out.  ATM, I can't duplicate this and I also
> can't see the diff you attached.  Thank you for taking the effort to
> provide it though.  I'm launching 1.2.0 tonight (which doesn't seem to
> have this problem.  Please test it as well.
>
> --
> Bug in file server: invalid trailing in directories on Windows
> https://bugs.launchpad.net/bugs/644958
> You received this bug notification because you are a direct subscriber
> of the bug.
>
> Status in Rocket Web Server: New
>
> Bug description:
> I am using Rocket 1.1.1 (Rocket-src-1.1.1.zip).
>
> Rocket's embedded fileserver (method='fs') adds invalid trailing to files inside subdirectories on Windows.
>
> How to duplicate (either cPython or Jython):
> - Run examples\fs.py within a folder that has a subdirectory ('data') and files in it ('data\data1.html')
> - Open subdirectory in browser ('http://localhost/data')
> - Instead of URL-style slash ('/'), file URLs are errorneously escaped with Windows-style slash ('\').
> - For instance: 'http://localhost/data\data1.html' -> should be 'http://localhost/data/data1.html'
>
> This behaviour becomes a problem when HTML files have relative references to files within same directory (for instance data1.css) since Windows-style backslashes are often not interpreted as trailing slashes (browser tries to retrieve 'http://localhost/data1.css' instead of 'http://localhost/data\data1.css')
>
>
> To unsubscribe from this bug, go to:
> https://bugs.launchpad.net/rocket/+bug/644958/+subscribe
>

Revision history for this message
Tim (tdfarrell) wrote :

I've applied the hacky fix in revision 126. I'll do a real fix it sometime in the near future.

Changed in rocket:
status: New → Fix Committed
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.