#29667: path converters don't handle spaces well. -------------------------------------+------------------------------------- Reporter: Keryn | Owner: nobody Knight | Type: Bug | Status: new Component: Core | Version: master (URLs) | Keywords: converters path Severity: Normal | _route_to_regex Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -------------------------------------+------------------------------------- This came up for someone on IRC last week, but I can't see that they raised a ticket about it.
Correct: {{{ >>> from django.urls.resolvers import _route_to_regex >>> _route_to_regex("<uuid:test>") ('^(?P<test>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})', {'test': <django.urls.converters.UUIDConverter at 0x1055e8c88>}) }}} Also working correctly: {{{ >>> from django.urls.resolvers import _route_to_regex >>> _route_to_regex("<uuid:2>") ImproperlyConfigured: URL route '<uuid:2>' uses parameter name '2' which isn't a valid Python identifier. }}} however, constructing a valid **looking** converter reference apparently hits neither the happy nor the unhappy path, and also I presume passes any system checks in place that might otherwise warn about the sensitivity: {{{ >>> from django.urls.resolvers import _route_to_regex >>> _route_to_regex("<uuid: test>") # note the preceeding space ('^\\<uuid\\:\\ test\\>', {}) }}} - the regex is invalid - the kwargs dictionary is (sort of rightly) empty. - the same is true with "test " and "te st" Unless I'm misunderstanding the code therein, "test ", " test" and "te st" should all be hitting the invalid identifier part, and personally I feel like leading/trailing spaces at least could just be sanitised (stripped) as they're almost certainly accidental or for display purposes. Tested in a shell against master @ 7eb556a6c2b2ac9313158f8b812eebea02a43f20. -- Ticket URL: <https://code.djangoproject.com/ticket/29667> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/052.7c3cdca8ec8089ff68b84007c546d99e%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.