Django

Code

Ticket #8381 (closed: fixed)

Opened 4 months ago

Last modified 3 months ago

Common middleware should use path_info

Reported by: jcassee Assigned to: nobody
Milestone: 1.0 Component: Uncategorized
Version: SVN Keywords: middleware
Cc: Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

The CommonMiddleware works its magic on request.path. Since changeset [8015] this should be request.path_info. Trivial patch attached.

Attachments

8381-r8423.diff (0.9 kB) - added by jcassee on 08/17/08 13:01:27.
8381-r8423-2.diff (0.9 kB) - added by jcassee on 08/18/08 06:57:35.

Change History

08/17/08 13:01:27 changed by jcassee

  • attachment 8381-r8423.diff added.

08/17/08 13:18:40 changed by mtredinnick

  • needs_better_patch changed.
  • needs_docs changed.
  • stage changed from Unreviewed to Accepted.
  • needs_tests changed.
  • milestone set to 1.0.

Have you actually tested this on a system with a non-empty SCRIPT_NAME or are you generating these patches just from code auditing? They need to be tested on an actual install before committing. I realise you can't write anything for Django's test suite for this -- such tests would be too fake to actually convey any confidence in affirming real-world behviour -- but can you at least confirm you've tested it manually.

08/17/08 14:02:27 changed by jcassee

Yes, I am using these changes on my own Django installation. The website uses my localeurl application that modifies request.path_info to strip a language prefix, so I run into these things. :-) This patch (and the one from #8376) work for me.

08/17/08 15:44:38 changed by mtredinnick

  • needs_better_patch set to 1.

This patch doesn't seem to be completely correct yet. The problem is when the new URL is constructed, it doesn't include the script name portion any longer. So the redirect (and any other uses of it) will be to the wrong location. Somewhere in the construction of newurl I would expect to see request.META['SCRIPT_NAME'], or, even better, a reuse of request.path once you've determined it does need a trailing slash added.

I suspect the solution might actually be as simple as not making the change on line 46 and only needing to make the one on line 57. But could you check that out, please? If you get to the redirect line, it looks like your current patch will lose the script name in the redirect. That shouldn't happen.

08/18/08 06:57:17 changed by jcassee

  • needs_better_patch deleted.

You are correct. I was testing the patch on my non-SCRIPT_NAME testing system. Thanks for your sharp eye!

Your solution is almost correct, I just had to fix the resolve check for the new url. I have updated the patch and tested it on my SCRIPT_NAME-enabled testing system.

08/18/08 06:57:35 changed by jcassee

  • attachment 8381-r8423-2.diff added.

08/20/08 20:32:18 changed by mtredinnick

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

(In [8456]) Fixed #8381 -- Fixed a problem with appending slashes in the common middleware when SCRIPT_NAME contains something other than '/'. Patch from jcassee.

Also fixed the middleware tests to work with this patch.


Add/Change #8381 (Common middleware should use path_info)




Change Properties
Action