Skip to content

Commit 10e0917

Browse files
authored
Merge pull request CloudBotIRC#192 from linuxdaemon/gonzobot+fix-url-end-chars
Fix valid end characters for link announcer regex
2 parents 75330cf + 004b11f commit 10e0917

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

plugins/link_announcer.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@ def no_parens(pattern):
3333
# Domain
3434
(?:
3535
# TODO Add support for IDNA hostnames as specified by RFC5891
36-
[\-.0-9A-Za-z]+| # host
37-
\d{1,3}(?:\.\d{1,3}){3}| # IPv4
38-
\[[A-F0-9]{0,4}(?::[A-F0-9]{0,4}){2,7}\] # IPv6
36+
(?:
37+
[\-.0-9A-Za-z]+| # host
38+
\d{1,3}(?:\.\d{1,3}){3}| # IPv4
39+
\[[A-F0-9]{0,4}(?::[A-F0-9]{0,4}){2,7}\] # IPv6
40+
)
41+
(?<![.,?!\]]) # Invalid end chars
3942
)
4043
4144
(?::\d*)? # port
4245
43-
(?:/(?:""" + no_parens(PATH_SEG_CHARS) + r""")*)*(?<![.,?!\]]) # Path segment
46+
(?:/(?:""" + no_parens(PATH_SEG_CHARS) + r""")*(?<![.,?!\]]))* # Path segment
4447
45-
(?:\?(?:""" + no_parens(QUERY_CHARS) + r""")*(?<![.,?!\]]))? # Query
48+
(?:\?(?:""" + no_parens(QUERY_CHARS) + r""")*(?<![.,!\]]))? # Query
4649
4750
(?:\#(?:""" + no_parens(FRAG_CHARS) + r""")*(?<![.,?!\]]))? # Fragment
4851
""",

tests/plugin_tests/test_link_announcer.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
"http://1337.net",
2828
"http://a.b-c.de",
2929
"http://223.255.255.254",
30+
"https://foo.bar/baz?#",
31+
"https://foo.bar/baz?",
3032
)
3133

3234
FAILS = (
@@ -55,6 +57,8 @@
5557
"https://foo.bar/baz.ext)",
5658
"https://foo.bar/test.",
5759
"https://foo.bar/test(test",
60+
"https://foo.bar.",
61+
"https://foo.bar./",
5862
)
5963

6064
SEARCH = (

0 commit comments

Comments
 (0)