Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[Downloader] Catch OSErrors from invalid repo names (#3029)
* [Downloader] Ensure repo names only contain the characters stated

* Create 2827.bugfix.rst

* [Downloader] Catch OSErrors from invalid filenames

* Update 2827.bugfix.rst

* Style

* do the thing again

* Update 2827.bugfix.rst
  • Loading branch information
Flame442 authored and Michael H committed Oct 5, 2019
1 parent ea77de5 commit 9b60816
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions changelog.d/downloader/2827.bugfix.rst
@@ -0,0 +1 @@
Repo names can now only contain the characters listed in the help text (A-Z, 0-9, underscores, and hyphens).
14 changes: 13 additions & 1 deletion redbot/cogs/downloader/downloader.py
@@ -1,6 +1,7 @@
import asyncio import asyncio
import contextlib import contextlib
import os import os
import re
import shutil import shutil
import sys import sys
from pathlib import Path from pathlib import Path
Expand Down Expand Up @@ -222,12 +223,17 @@ async def repo(self, ctx):
async def _repo_add(self, ctx, name: str, repo_url: str, branch: str = None): async def _repo_add(self, ctx, name: str, repo_url: str, branch: str = None):
"""Add a new repo. """Add a new repo.
The name can only contain characters A-z, numbers and underscores. Repo names can only contain characters A-z, numbers, underscores, and hyphens.
The branch will be the default branch if not specified. The branch will be the default branch if not specified.
""" """
agreed = await do_install_agreement(ctx) agreed = await do_install_agreement(ctx)
if not agreed: if not agreed:
return return
if re.match("^[a-zA-Z0-9_\-]*$", name) is None:
await ctx.send(
_("Repo names can only contain characters A-z, numbers, underscores, and hyphens.")
)
return
try: try:
# noinspection PyTypeChecker # noinspection PyTypeChecker
repo = await self._repo_manager.add_repo(name=name, url=repo_url, branch=branch) repo = await self._repo_manager.add_repo(name=name, url=repo_url, branch=branch)
Expand All @@ -241,6 +247,12 @@ async def _repo_add(self, ctx, name: str, repo_url: str, branch: str = None):
branch, branch,
exc_info=err, exc_info=err,
) )
except OSError:
await ctx.send(
_(
"Something went wrong trying to add that repo. Your repo name might have an invalid character."
)
)
else: else:
await ctx.send(_("Repo `{name}` successfully added.").format(name=name)) await ctx.send(_("Repo `{name}` successfully added.").format(name=name))
if repo.install_msg is not None: if repo.install_msg is not None:
Expand Down

0 comments on commit 9b60816

Please sign in to comment.