-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3173 from artragis/feature_url
Force la cohérence des protocoles pour le chargement des ressources
- Loading branch information
Showing
5 changed files
with
38 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from django import template | ||
from zds.settings import ZDS_APP | ||
|
||
|
||
register = template.Library() | ||
|
||
|
||
@register.filter('remove_url_protocole') | ||
def remove_url_protocole(input_url): | ||
""" | ||
make every image url pointing to this website protocol independant so that https is not broken | ||
""" | ||
if ZDS_APP["site"]["dns"] in input_url: | ||
return input_url.replace("http:/", "https:/").replace("https://" + ZDS_APP["site"]["dns"], "") | ||
return input_url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from zds.settings import ZDS_APP | ||
from django.test import TestCase | ||
from zds.utils.templatetags.remove_url_protocole import remove_url_protocole | ||
|
||
|
||
class RemoveUrlProtocolTest(TestCase): | ||
|
||
def test_remove_protocole_when_local_url(self): | ||
self.assertEqual("/bla.html", remove_url_protocole("http://" + ZDS_APP["site"]["dns"] + "/bla.html")) | ||
self.assertEqual("/bla.html", remove_url_protocole("https://" + ZDS_APP["site"]["dns"] + "/bla.html")) | ||
|
||
def test_no_change_when_no_protocole(self): | ||
self.assertEqual("/bla.html", remove_url_protocole("/bla.html")) | ||
|
||
def test_no_change_when_extern_address(self): | ||
self.assertEqual("http://www.google.com/bla.html", remove_url_protocole("http://www.google.com/bla.html")) |