MCPcopy
hub / github.com/django/django / escape_leading_slashes

Function escape_leading_slashes

django/utils/http.py:308–316  ·  view source on GitHub ↗

If redirecting to an absolute path (two leading slashes), a slash must be escaped to prevent browsers from handling the path as schemaless and redirecting to another host.

(url)

Source from the content-addressed store, hash-verified

306
307
308def escape_leading_slashes(url):
309 """
310 If redirecting to an absolute path (two leading slashes), a slash must be
311 escaped to prevent browsers from handling the path as schemaless and
312 redirecting to another host.
313 """
314 if url.startswith("//"):
315 url = "/%2F{}".format(url.removeprefix("//"))
316 return url
317
318
319def _parseparam(s):

Callers 3

_reverse_with_prefixMethod · 0.90
testMethod · 0.90

Calls 1

formatMethod · 0.45

Tested by 1

testMethod · 0.72