Skip to content
Myr

glob expansion on Windows doesn't fail on invalid values

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Lord · committed by David Lord · parent deb1f0e · Browse files · 3 files+14 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+14 added−2 removed

  • tests:+2 added−0 removed
  • other:+12 added−2 removed

3 files+14 added−2 removed

modified:src/click/utils.py+10 added-2 removed
1import os2import re3import sys4import typing as t5from functools import update_wrapper6from types import ModuleType
529 unmodified lines
536537 See :func:`glob.glob`, :func:`os.path.expanduser`, and538 :func:`os.path.expandvars`.539539 This intended for use on Windows, where the shell does not do any540 This is intended for use on Windows, where the shell does not do any541 expansion. It may not exactly match what a Unix shell would do.542543 :param args: List of command line arguments to expand.544 :param user: Expand user home directory.545 :param env: Expand environment variables.546 :param glob_recursive: ``**`` matches directories recursively.547548 .. versionchanged:: 8.1549 Invalid glob patterns are treated as empty expansions rather550 than raising an error.551552 .. versionadded:: 8.0553554 :meta private:555 """
7 unmodified lines
563564 if env:565 arg = os.path.expandvars(arg)566567 try:562 matches = glob(arg, recursive=glob_recursive)568 matches = glob(arg, recursive=glob_recursive)569 except re.error:570 matches = []571572 if not matches:573 out.append(arg)574 else:
3 unmodified lines
modified:tests/test_utils.py+2 added
466 unmodified lines
467 assert "hello" in click.utils._expand_args(["$CLICK_TEST"])468 assert "setup.cfg" in click.utils._expand_args(["*.cfg"])469 assert os.path.join("docs", "conf.py") in click.utils._expand_args(["**/conf.py"])470 assert "*.not-found" in click.utils._expand_args(["*.not-found"])471 # a bad glob pattern, such as a pytest identifier, should return itself472 assert click.utils._expand_args(["test.py::test_bad"])[0] == "test.py::test_bad"473474475@pytest.mark.parametrize(476 ("value", "max_length", "expect"),
32 unmodified lines
modified:CHANGES.rst+2 added
36 unmodified lines
37 strings. Processing is only done when formatting help text for38 output. :issue:`2149`39- Allow empty str input for ``prompt()`` when40 ``confirmation_prompt=True`` and ``default=""``. :issue:`2157`41- Windows glob pattern expansion doesn't fail if a value is an invalid42 pattern. :issue:`2195`434445Version 8.0.446-------------
948 unmodified lines