Skip to content

Commit 5a79f89

Browse files
authored
fix(metrics): update the polynomial regular expression used on uncontrolled data (bytedance#784)
1 parent cd5c487 commit 5a79f89

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/eval/metrics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def count_words(text: str) -> int:
125125

126126
def count_citations(text: str) -> int:
127127
"""Count markdown-style citations [text](url)."""
128-
pattern = r"\[.+?\]\(https?://[^\s\)]+\)"
128+
pattern = r"\[[^\]]*\]\(https?://[^\s\)]+\)"
129129
return len(re.findall(pattern, text))
130130

131131

@@ -148,7 +148,7 @@ def extract_domains(text: str) -> List[str]:
148148

149149
def count_images(text: str) -> int:
150150
"""Count markdown images ![alt](url)."""
151-
pattern = r"!\[.*?\]\(.+?\)"
151+
pattern = r"!\[[^\]]*\]\([^)]+\)"
152152
return len(re.findall(pattern, text))
153153

154154

0 commit comments

Comments
 (0)