summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Lord <davidism@gmail.com>2022-02-21 13:25:30 -0800
committerDavid Lord <davidism@gmail.com>2022-02-21 13:25:30 -0800
commit3699bcccbad2073e307837a8f8d389bf2530f871 (patch)
tree35e21bb71cc9d0ede305261f5fdde1ba17448771 /src
parentdeb1f0e1d736774ae17ce423ba452de937ffa402 (diff)
downloadclick-3699bcccbad2073e307837a8f8d389bf2530f871.tar.gz
glob expansion on Windows doesn't fail on invalid values
Diffstat (limited to 'src')
-rw-r--r--src/click/utils.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/click/utils.py b/src/click/utils.py
index 2525e98..467b7b6 100644
--- a/src/click/utils.py
+++ b/src/click/utils.py
@@ -1,4 +1,5 @@
import os
+import re
import sys
import typing as t
from functools import update_wrapper
@@ -536,7 +537,7 @@ def _expand_args(
See :func:`glob.glob`, :func:`os.path.expanduser`, and
:func:`os.path.expandvars`.
- This intended for use on Windows, where the shell does not do any
+ This is intended for use on Windows, where the shell does not do any
expansion. It may not exactly match what a Unix shell would do.
:param args: List of command line arguments to expand.
@@ -544,6 +545,10 @@ def _expand_args(
:param env: Expand environment variables.
:param glob_recursive: ``**`` matches directories recursively.
+ .. versionchanged:: 8.1
+ Invalid glob patterns are treated as empty expansions rather
+ than raising an error.
+
.. versionadded:: 8.0
:meta private:
@@ -559,7 +564,10 @@ def _expand_args(
if env:
arg = os.path.expandvars(arg)
- matches = glob(arg, recursive=glob_recursive)
+ try:
+ matches = glob(arg, recursive=glob_recursive)
+ except re.error:
+ matches = []
if not matches:
out.append(arg)