MCPcopy Create free account
hub / github.com/executablebooks/markdown-it-py / validateLink

Function validateLink

markdown_it/common/normalize_url.py:70–81  ·  view source on GitHub ↗

Validate URL link is allowed in output. This validator can prohibit more than really needed to prevent XSS. It's a tradeoff to keep code simple and to be secure by default. Note: url should be normalized at this point, and existing entities decoded.

(url: str, validator: Callable[[str], bool] | None = None)

Source from the content-addressed store, hash-verified

68
69
70def validateLink(url: str, validator: Callable[[str], bool] | None = None) -> bool:
71 """Validate URL link is allowed in output.
72
73 This validator can prohibit more than really needed to prevent XSS.
74 It's a tradeoff to keep code simple and to be secure by default.
75
76 Note: url should be normalized at this point, and existing entities decoded.
77 """
78 if validator is not None:
79 return validator(url)
80 url = url.strip().lower()
81 return bool(GOOD_DATA_RE.search(url)) if BAD_PROTO_RE.search(url) else True

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…