Opened 17 years ago

Closed 17 years ago

Last modified 22 months ago

#5090 closed Uncategorized (wontfix)

Url patterns are case-sensitive.

Reported by: Alex Nickolaenkov <nickolaenkov@…> Owned by: Malcolm Tredinnick
Component: HTTP handling Version: dev
Severity: Normal Keywords: url handling
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


the following urls are treated as different:[[BR]]

urls are taken from the tutorial. To reproduce just change the case of letters. I think this is a MAJOR but because it reproduces in the production.

Take a look: 200 OK BAD 404 response

objects RegexURLPattern, RegexURLResolver have the same piece of code:
self.regex = re.compile(regex, re.UNICODE)
change at least to
self.regex = re.compile(regex, re.UNICODE | re.IGNORECASE)
and the things are done.

Attachments (1) (12.1 KB ) - added by Alex Nickolaenkov <nickolaenkov@…> 17 years ago.
simplies patch

Download all attachments as: .zip

Change History (8)

by Alex Nickolaenkov <nickolaenkov@…>, 17 years ago

Attachment: added

simplies patch

comment:1 by Chris Beaven, 17 years ago

Resolution: wontfix
Status: newclosed

Different case URLs should be treated as such because they aren't the same. Feel free to bring this up in the Django Dev group, but I really don't think you're going to win this one.

In the future, provide a diff patch as opposed to just attaching your version of the modified file.

comment:2 by Alex Nickolaenkov <nickolaenkov@…>, 17 years ago

Resolution: wontfix
Status: closedreopened

Brought to Dev group.

The following letter:

Hello guys,

Django is positioned as a tool for perfectionists. So there is a
few questions which are very valuable for guys making the best web-sites:

  • Case-sensitive urls. Take a look: The urls are pretty same. But the second one causes 404 Response. While typing the second url the user tries to access typing its address and types "Simpsons" instead of "simpsons". In terms of nix-like systems this is a major difference.. But nix systems are designed for professionals, not for my 50 year old aunt browsing the Internet. She knows nothing about different interpretation of letters in the computer world. When I was watching google video about django (by Jacob) I though: Hey, some cool guys finally understood that crappy urls are bad. Let's do some more work and make urls usable and accessible. Furthermore if user sees 404 error instead of page one was looking for, that's not his loss, that is a loss of the site. What do you think?

I've posted corresponding ticket.
Now it is closed as "won't fix". At least the resolution should be
changed to "By Design" if you guys don't like sites built on django
being convenient.

Here is an example of case-insensitive urls. They rock:

  • What do you think about including Web Typography support as a built-in django feature?

Best regards,

Alex mailto:nikolaenkov@…

comment:3 by Jacob, 17 years ago

Resolution: wontfix
Status: reopenedclosed

What SmileyChris said.

comment:4 by anonymous, 17 years ago

You can handle case-(in)sensitivity in your views. Conversely, if URLs were case-insensitive by default, it would be hard or impossible to change them into case-sensitive within views, so it would be a net loss of functionality.

comment:5 by Velmont, 15 years ago

You can just use the regex to check without case sensitivity.

in reply to:  2 comment:6 by anonymous, 10 years ago

Easy pickings: unset
Severity: Normal
Type: Uncategorized
UI/UX: unset

Replying to Alex Nickolaenkov <nickolaenkov@…>:

Actually, your example is wrong, since the URL will work correctly. Suppose they are using Django, they would be using case insensitive regexes ((?i) prefix, per 5), but their object lookup query is not case-insensitive. They would have to use Article.objects.get(slug__iexact="Simpsons") in addition to the case-insensitive regex for the whole mechanism to work.

comment:7 by Lia Va, 22 months ago

What if just add, say ipath and re_ipath.
I even have an example of such code in my project:

import re
from functools import partial

from django.urls.resolvers import RoutePattern, RegexPattern, _route_to_regex
from django.urls.conf import _path
from django.core.exceptions import ImproperlyConfigured

class IRoutePattern(RoutePattern):
    def _compile(self, route):
        return re.compile(_route_to_regex(route, self._is_endpoint)[0], re.IGNORECASE)

class IRegexPattern(RegexPattern):
    def _compile(self, regex):
        """Compile and return the given regular expression."""
            return re.compile(regex, re.IGNORECASE)
        except re.error as e:
            raise ImproperlyConfigured(
                '"%s" is not a valid regular expression: %s' % (regex, e)
            ) from e

ipath = partial(_path, Pattern=IRoutePattern)
re_ipath = partial(_path, Pattern=IRegexPattern)
Note: See TracTickets for help on using tickets.
Back to Top