Repository: praw-dev/praw

Issue:
IndexError on Invalid URL to Submission
**Describe the bug**
<!-- A clear and concise description of what the bug is. -->

If I give a URL of the form `https://reddit.com/comments` or `https://www.reddit.com/r/test/comments`, it returns an IndexError rather than InvalidURL. Strangely enough `https://redd.it` is not affected.

**To Reproduce**
Steps to reproduce the behavior:
1. `reddit.submission(url="https://www.reddit.com/r/test/comments/")`
2. `reddit.submission(url="https://reddit.com/comments/")`

**Expected behavior**
<!-- A clear and concise description of what you expected to happen. -->
An InvalidURL to be raised.

**Code/Logs**
<!-- include your code, without the Reddit() initialization, so as to not leak private credentials. -->
```python
IndexError                                Traceback (most recent call last)
<ipython-input-14-87a53f614e22> in <module>
----> 1 reddit.submission(url="https://reddit.com/comments/")

~/.local/share/virtualenvs/tmp-agwWamBd/lib/python3.8/site-packages/praw/reddit.py in submission(self, id, url)
    798
    799         """
--> 800         return models.Submission(self, id=id, url=url)

~/.local/share/virtualenvs/tmp-agwWamBd/lib/python3.8/site-packages/praw/models/reddit/submission.py in __init__(self, reddit, id, url, _data)
    538             self.id = id
    539         elif url is not None:
--> 540             self.id = self.id_from_url(url)
    541
    542         self._comments_by_id = {}

~/.local/share/virtualenvs/tmp-agwWamBd/lib/python3.8/site-packages/praw/models/reddit/submission.py in id_from_url(url)
    422                 )
    423         else:
--> 424             submission_id = parts[parts.index("comments") + 1]
    425
    426         if not submission_id.isalnum():

IndexError: list index out of range
```

**System Info**
 - OS: Mac OS 10.15.6
 - Python: 3.8.5
 - PRAW Version: 7.1.0


Discussion:
bboe: Can you please rebase and resolve the conflicts?

Patch:
diff --git a/AUTHORS.rst b/AUTHORS.rst
index d5d428d0..e4df8b73 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -64,4 +64,5 @@ Source Contributors
 - Todd Roberts `@toddrob99 <https://github.com/toddrob99>`_
 - MaybeNetwork `@MaybeNetwork <https://github.com/MaybeNetwork>`_
 - Nick Kelly `@nickatnight <https://github.com/nickatnight>`_
+- Yash Chhabria `@Cyatos <https://github.com/Cyatos>`_
 <!-- - Add "Name <email (optional)> and github profile link" above this line. -->
diff --git a/CHANGES.rst b/CHANGES.rst
index aab23ea3..daeb776f 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -27,6 +27,7 @@ Unreleased
 **Fixed**
 
 * An issue where leaving as a moderator fails if you are using token auth.
+* An issue where an incorrect error was being raised due to invalid submission urls.
 
 7.1.0 (2020/06/22)
 ------------------
diff --git a/praw/models/reddit/submission.py b/praw/models/reddit/submission.py
index 3a90d043..23acf718 100644
--- a/praw/models/reddit/submission.py
+++ b/praw/models/reddit/submission.py
@@ -418,8 +418,13 @@ class Submission(SubmissionListingMixin, UserContentMixin, FullnameMixin, Reddit
                 raise InvalidURL(
                     url, message="Invalid URL (subreddit, not submission): {}"
                 )
+
         elif "gallery" in parts:
             submission_id = parts[parts.index("gallery") + 1]
+
+        elif parts[-1] == "comments":
+            raise InvalidURL(url, message="Invalid URL (submission id not present): {}")
+
         else:
             submission_id = parts[parts.index("comments") + 1]
 


Test patch:
diff --git a/tests/unit/models/reddit/test_submission.py b/tests/unit/models/reddit/test_submission.py
index 6a5c75ad..75840ab0 100644
--- a/tests/unit/models/reddit/test_submission.py
+++ b/tests/unit/models/reddit/test_submission.py
@@ -85,6 +85,8 @@ class TestSubmission(UnitTest):
             "http://reddit.com/comments/_/2gmzqe",
             "https://reddit.com/r/wallpapers/",
             "https://reddit.com/r/wallpapers",
+            "https://www.reddit.com/r/test/comments/",
+            "https://reddit.com/comments/",
         ]
         for url in urls:
             with pytest.raises(ClientException):