8000 gh-543 Update regex to include hyphens in username · goodwillcoding/github3.py@83337c9 · GitHub
[go: up one dir, main page]

Skip to content 8000

Commit 83337c9

Browse files
committed
sigmavirus24gh-543 Update regex to include hyphens in username
Fix bug where a username which contains a hyphen cannot be used in the `GitHub.pubsubhubbub` method.
1 parent 5c85bd1 commit 83337c9

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

github3/github.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,7 +998,8 @@ def pubsubhubbub(self, mode, topic, callback, secret=''):
998998
:returns: bool
999999
"""
10001000
from re import match
1001-
m = match('https?://[\w\d\-\.\:]+/\w+/[\w\._-]+/events/\w+', topic)
1001+
m = match('https?://[\w\d\-\.\:]+/\w[\w-]+\w/[\w\._-]+/events/\w+',
1002+
topic)
10021003
status = False
10031004
if mode and topic and callback and m:
10041005
data = [('hub.mode', mode), ('hub.topic', topic),

tests/unit/test_github.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,32 @@ def test_pubsubhubbub(self):
416416
}
417417
)
418418

419+
def test_pubsubhubbub_invalid_username(self):
420+
"""Verify a valid call with invalid username does not call post."""
421+
topic = (
422+
'hub.topic',
423+
'https://github.com/-octocat/hello-world/events/push'
424+
)
425+
body = [('hub.mode', 'subscribe'),
426+
topic,
427+
('hub.callback', 'https://localhost/post')]
428+
data = dict([(k[4:], v) for k, v in body])
429+
self.instance.pubsubhubbub(**data)
430+
assert self.session.post.called is False
431+
432+
def test_pubsubhubbub_valid_username(self):
433+
"""Verify a valid call with valid username calls post."""
434+
topic = (
435+
'hub.topic',
436+
'https://github.com/o-cto-ca-t/hello-world/events/push'
437+
)
438+
body = [('hub.mode', 'subscribe'),
439+
topic,
440+
('hub.callback', 'https://localhost/post')]
441+
data = dict([(k[4:], v) for k, v in body])
442+
self.instance.pubsubhubbub(**data)
443+
assert self.session.post.called is True
444+
419445
def test_pubsubhubbub_secret(self):
420446
"""Verify the request for creating a pubsubhubbub hook."""
421447
topic = (

0 commit comments

Comments
 (0)
0