Skip to content

Commit

Permalink
🐛 [#32] Remove port number before using validate_host
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Apr 16, 2024
1 parent e3325e7 commit 6acc688
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 3 additions & 3 deletions django_loose_fk/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from django.utils.functional import LazyObject, empty
from django.utils.module_loading import import_string

from .utils import get_resource_for_path
from .utils import get_resource_for_path, strip_port_number
from .virtual_models import get_model_instance

SETTING = "DEFAULT_LOOSE_FK_LOADER"
Expand Down Expand Up @@ -55,12 +55,12 @@ def is_local_url(self, url: str) -> bool:
"break django-loose-fk's behaviour. You should use an explicit list.",
RuntimeWarning,
)
return validate_host(parsed.netloc, allowed_hosts)
return validate_host(strip_port_number(parsed.netloc), allowed_hosts)

if local_base_urls:
return any(url.startswith(base_url) for base_url in local_base_urls)

return validate_host(parsed.netloc, allowed_hosts)
return validate_host(strip_port_number(parsed.netloc), allowed_hosts)

def load_local_object(self, url: str, model: ModelBase) -> models.Model:
parsed = urlparse(url)
Expand Down
4 changes: 4 additions & 0 deletions django_loose_fk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,7 @@ def get_subclasses(cls):
for subclass in cls.__subclasses__():
yield from get_subclasses(subclass)
yield subclass


def strip_port_number(netloc: str) -> str:
return netloc.split(":")[0]

0 comments on commit 6acc688

Please sign in to comment.