File tree Expand file tree Collapse file tree 2 files changed +18
-3
lines changed
Expand file tree Collapse file tree 2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change 77from cloudbot import hook
88from cloudbot .hook import Priority , Action
99
10+ ENCODED_CHAR = r"%[A-F0-9]{2}"
11+ PATH_SEG_CHARS = r"[A-Za-z0-9!$&'*-.:;=@_~\u00A0-\U0010FFFD]|" + ENCODED_CHAR
12+ QUERY_CHARS = PATH_SEG_CHARS + r"|/"
13+ FRAG_CHARS = QUERY_CHARS
14+
15+
16+ def no_parens (pattern ):
17+ return r"{0}|\(({0}|[\(\)])*\)" .format (pattern )
18+
19+
1020# This will match any URL, blacklist removed and abstracted to a priority/halting system
1121url_re = re .compile (
1222 r"""
3040
3141 (?::\d*)? # port
3242
33- (?:/(?:[A-Za-z0-9!$&-.:;=@_~\u00A0-\U0010FFFD]|%[A-F0-9]{2})*)* # Path segment
43+ (?:/(?:""" + no_parens ( PATH_SEG_CHARS ) + r""")*)*(?<![.,?!\]]) # Path segment
3444
35- (?:\?(?:[A-Za-z0-9!$&-;=@_~\u00A0-\U0010FFFD]|%[A-F0-9]{2})* )? # Query
45+ (?:\?(?:""" + no_parens ( QUERY_CHARS ) + r""")*(?<![.,?!\]]) )? # Query
3646
37- (?:\#(?:[A-Za-z0-9!$&-;=@_~\u00A0-\U0010FFFD]|%[A-F0-9]{2})* )? # Fragment
47+ (?:\#(?:""" + no_parens ( FRAG_CHARS ) + r""")*(?<![.,?!\]]) )? # Fragment
3848 """ ,
3949 re .IGNORECASE | re .VERBOSE
4050)
Original file line number Diff line number Diff line change 3131
3232FAILS = (
3333 "http://" ,
34+ "http://." ,
35+ "http://.." ,
3436 "http://?" ,
3537 "http://??" ,
3638 "http://??/" ,
5052 ":// should fail" ,
5153 "http://foo.bar/foo(bar)baz quux" ,
5254 "ftps://foo.bar/" ,
55+ "https://foo.bar/baz.ext)" ,
56+ "https://foo.bar/test." ,
57+ "https://foo.bar/test(test" ,
5358)
5459
5560SEARCH = (
You can’t perform that action at this time.
0 commit comments