Opened 17 years ago

Closed 17 years ago

Last modified 19 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

Description

the following urls are treated as different:
http://127.0.0.1:8000/now/PLUS4HOURS/[[BR]]
and
http://127.0.0.1:8000/now/plus4hours/[[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:

http://www.coastalbeat.com/news/2007/jul/30/simpsons/ 200 OK

http://www.coastalbeat.com/news/2007/jul/30/Simpsons/ BAD 404 response


FIX:
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)

urlresolvers.py (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: urlresolvers.py 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: http://www.coastalbeat.com/news/2007/jul/30/simpsons/ http://www.coastalbeat.com/news/2007/jul/30/Simpsons/ 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.
http://code.djangoproject.com/ticket/5090
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:
http://www.askeri.ru/PUBLISH/
http://www.askeri.ru/publish/

  • 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, 14 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 http://www.gonaples.com/news/2007/Jul/30/simpsons/ 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, 19 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."""
        try:
            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