Merge pull request #230 from michael-lazar/slash_subreddit

Check for empty subreddit name.
This commit is contained in:
Michael Lazar
2016-06-14 01:09:02 -07:00
committed by GitHub
2 changed files with 15 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ from datetime import datetime
import six import six
import praw import praw
from praw.errors import InvalidSubreddit
from kitchen.text.display import wrap from kitchen.text.display import wrap
from . import exceptions from . import exceptions
@@ -398,6 +399,11 @@ class SubredditContent(Content):
submissions = reddit.search(query, subreddit=name, sort=order) submissions = reddit.search(query, subreddit=name, sort=order)
else: else:
if name == '':
# Praw does not correctly handle empty strings
# https://github.com/praw-dev/praw/issues/615
raise InvalidSubreddit()
if name == 'front': if name == 'front':
dispatch = { dispatch = {
None: reddit.get_front_page, None: reddit.get_front_page,

View File

@@ -259,6 +259,14 @@ def test_content_subreddit_from_name(reddit, terminal):
SubredditContent.from_name(reddit, name, terminal.loader) SubredditContent.from_name(reddit, name, terminal.loader)
assert isinstance(terminal.loader.exception, exceptions.SubredditError) assert isinstance(terminal.loader.exception, exceptions.SubredditError)
# A couple of edge cases
names = ['', '/', '//', '/////////////////']
for name in names:
with terminal.loader():
SubredditContent.from_name(reddit, name, terminal.loader)
assert isinstance(terminal.loader.exception,
praw.errors.InvalidSubreddit)
# Front page alias # Front page alias
name = '/r/front/rising' name = '/r/front/rising'
content = SubredditContent.from_name(reddit, name, terminal.loader) content = SubredditContent.from_name(reddit, name, terminal.loader)
@@ -344,4 +352,4 @@ def test_content_subscription_empty(terminal):
with terminal.loader(): with terminal.loader():
SubscriptionContent(subscriptions, terminal.loader) SubscriptionContent(subscriptions, terminal.loader)
assert isinstance(terminal.loader.exception, exceptions.SubscriptionError) assert isinstance(terminal.loader.exception, exceptions.SubscriptionError)