supercodepoet/django-merlin — Issue #12: _get_url_base fails if url string contains same name as the slug
Author: cgallemore
Created: 2011-12-27 16:29:22+00:00
State: open

If the url string contains the same name as the slug in the request path _get_url_base fails and returns only part of the base URL.

For example, I had the url /registration/business/buy-referral/referral and _get_url_base only returned /registration/business/buy-

This issue is that _get_url_base uses:

index = request.path.find(step.slug)

which returns the first instance of the slug found (in my case referral). If _get_url_base instead used:

index = request.path.rindex(step.slug)

This would have returned the proper path, since it's starts searching from the right first, where the slug would be.

>>> slug = '/registration/business/buy-referral/referral'
>>> slug[:slug.find('referral')]
'/registration/business/buy-'
>>> slug[:slug.rindex('referral')]
'/registration/business/buy-referral/'
>>>