Check for empty subreddit name.
This commit is contained in:
@@ -6,6 +6,7 @@ from datetime import datetime
|
||||
|
||||
import six
|
||||
import praw
|
||||
from praw.errors import InvalidSubreddit
|
||||
from kitchen.text.display import wrap
|
||||
|
||||
from . import exceptions
|
||||
@@ -398,6 +399,11 @@ class SubredditContent(Content):
|
||||
submissions = reddit.search(query, subreddit=name, sort=order)
|
||||
|
||||
else:
|
||||
if name == '':
|
||||
# Praw does not correctly handle empty strings
|
||||
# https://github.com/praw-dev/praw/issues/615
|
||||
raise InvalidSubreddit()
|
||||
|
||||
if name == 'front':
|
||||
dispatch = {
|
||||
None: reddit.get_front_page,
|
||||
|
||||
@@ -259,6 +259,13 @@ def test_content_subreddit_from_name(reddit, terminal):
|
||||
SubredditContent.from_name(reddit, name, terminal.loader)
|
||||
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, exceptions.SubredditError)
|
||||
|
||||
# Front page alias
|
||||
name = '/r/front/rising'
|
||||
content = SubredditContent.from_name(reddit, name, terminal.loader)
|
||||
|
||||
Reference in New Issue
Block a user