Skip to content

Commit 9eb841b

Browse files
committed
Better url regex (not vulnerable to ReDoS)
1 parent 182b444 commit 9eb841b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

discord_markdown_ast_parser/lexer.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,9 @@ def __call__(self, text: str):
1515
def __repr__(self):
1616
return f"{self.__class__.__name__}({self.regex and self.regex.pattern!r})"
1717

18-
# stolen from https://www.urlregex.com/
19-
URL_REGEX = (
20-
r"http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+"
21-
)
18+
19+
URL_REGEX = r"https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,4}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)"
20+
2221

2322
class LexingRule(Lexing, Enum):
2423
USER_MENTION = r"<@!?(\d{15,20})>"

0 commit comments

Comments
 (0)