fix(metrics): update the polynomial regular expression used on uncontrolled data (#784)

This commit is contained in:
Willem Jiang 2025-12-26 10:10:12 +08:00 committed by GitHub
parent cd5c4877f3
commit 5a79f896c4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -125,7 +125,7 @@ def count_words(text: str) -> int:
def count_citations(text: str) -> int:
"""Count markdown-style citations [text](url)."""
pattern = r"\[.+?\]\(https?://[^\s\)]+\)"
pattern = r"\[[^\]]*\]\(https?://[^\s\)]+\)"
return len(re.findall(pattern, text))
@ -148,7 +148,7 @@ def extract_domains(text: str) -> List[str]:
def count_images(text: str) -> int:
"""Count markdown images ![alt](url)."""
pattern = r"!\[.*?\]\(.+?\)"
pattern = r"!\[[^\]]*\]\([^)]+\)"
return len(re.findall(pattern, text))