wcs: don't create crypto url for local path (#63476)

This commit is contained in:
Frédéric Péters 2022-04-01 17:21:47 +02:00
parent a1dd7f7569
commit f7913715a1
2 changed files with 16 additions and 1 deletions

View File

@ -14,6 +14,8 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import urllib.parse
from django import template
from django.conf import settings
from django.urls import reverse
@ -96,7 +98,7 @@ def format_text(field, value):
@register.simple_tag(takes_context=True)
def make_public_url(context, url):
if not url or not is_url_from_known_service(url):
if not url or not is_url_from_known_service(url) or not urllib.parse.urlparse(url).netloc:
return url
if hasattr(context, 'request'):
request = context.request

View File

@ -735,6 +735,19 @@ def test_json_cell_make_public_url(app):
assert 'XNoneY' in resp.text
assert '/api/wcs/file/' not in resp.text
# url as "None" as string
cell.template_string = '{% make_public_url url="None" %}'
cell.save()
with mock.patch('combo.utils.requests.get') as requests_get:
data = {'data': []}
requests_get.return_value = mock_json_response(content=json.dumps(data), status_code=200)
url = reverse(
'combo-public-ajax-page-cell', kwargs={'page_pk': page.id, 'cell_reference': cell.get_reference()}
)
resp = app.get(url)
assert resp.text == 'None'
def test_json_cell_validity(context):
page = Page.objects.create(title='example page', slug='example-page')