jazzband / django-hosts

Dynamic and static host resolving for Django. Maps hostnames to URLconfs.
http://django-hosts.rtfd.org
Other
982 stars 106 forks source link

Regex artifact in hosts #158

Open Amith225 opened 1 year ago

Amith225 commented 1 year ago

consider the following host: host(fr'^api', 'api.urls', name='api')

i went through the codebase and found self.compiled_regex = re.compile(r'%s%s(\.|:|$)' % (regex, suffix)) now internally the complied_regex = re.compile('^api(\\.|:|$)')

this creates a problem, if i go to api.localhost this works as expected, but if I go to api.xyz.localhost it still routes me to api.urls

so maybe change the complied_regex to re.compile(r'%s%s(:[0-9]+)?$)' % (regex, suffix)) ? this will ensure the regex follows parent_host and is either followed by a port with atleast one digit, or no port at all

but this will also force user to give the parent_host, which i think would not be a major problem

if this makes sense, and is ok, i would like to be assigned for this