Repository: xonsh/xonsh

Issue:
Regex globbing broken for path including active regex characters
Paths including active regex characters such as `test+a/model` are not matched by regex globbing:

```xonsh
mkdir -p test/model
mkdir -p test+a/model
mkdir -p test*1/model
for d in `.*/model`:
    print(d)
```

Gives the following output

```output
test/model
```

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**


Comments:

Patch:
diff --git a/news/fix-globbing-path-containing-regex.rst b/news/fix-globbing-path-containing-regex.rst
new file mode 100644
index 00000000..30e06e20
--- /dev/null
+++ b/news/fix-globbing-path-containing-regex.rst
@@ -0,0 +1,23 @@
+**Added:**
+
+* <news item>
+
+**Changed:**
+
+* <news item>
+
+**Deprecated:**
+
+* <news item>
+
+**Removed:**
+
+* <news item>
+
+**Fixed:**
+
+* Fixed regex globbing for file paths that contain special regex characters (e.g. "test*1/model")
+
+**Security:**
+
+* <news item>
diff --git a/xonsh/built_ins.py b/xonsh/built_ins.py
index 737347ce..cd83ef8b 100644
--- a/xonsh/built_ins.py
+++ b/xonsh/built_ins.py
@@ -20,7 +20,7 @@ from ast import AST
 
 from xonsh.inspectors import Inspector
 from xonsh.lazyasd import lazyobject
-from xonsh.platform import ON_POSIX, ON_WINDOWS
+from xonsh.platform import ON_POSIX
 from xonsh.tools import (
     XonshCalledProcessError,
     XonshError,
@@ -92,12 +92,7 @@ def reglob(path, parts=None, i=None):
             base = ""
         elif len(parts) > 1:
             i += 1
-    regex = os.path.join(base, parts[i])
-    if ON_WINDOWS:
-        # currently unable to access regex backslash sequences
-        # on Windows due to paths using \.
-        regex = regex.replace("\\", "\\\\")
-    regex = re.compile(regex)
+    regex = re.compile(parts[i])
     files = os.listdir(subdir)
     files.sort()
     paths = []
@@ -105,12 +100,12 @@ def reglob(path, parts=None, i=None):
     if i1 == len(parts):
         for f in files:
             p = os.path.join(base, f)
-            if regex.fullmatch(p) is not None:
+            if regex.fullmatch(f) is not None:
                 paths.append(p)
     else:
         for f in files:
             p = os.path.join(base, f)
-            if regex.fullmatch(p) is None or not os.path.isdir(p):
+            if regex.fullmatch(f) is None or not os.path.isdir(p):
                 continue
             paths += reglob(p, parts=parts, i=i1)
     return paths
diff --git a/xonsh/dirstack.py b/xonsh/dirstack.py
index b73a1ac8..91ffb925 100644
--- a/xonsh/dirstack.py
+++ b/xonsh/dirstack.py
@@ -20,6 +20,7 @@ _unc_tempDrives: tp.Dict[str, str] = {}
 """ drive: sharePath for temp drive letters we create for UNC mapping"""
 
 
+@tp.no_type_check
 def _unc_check_enabled() -> bool:
     r"""Check whether CMD.EXE is enforcing no-UNC-as-working-directory check.
 


Test patch:
diff --git a/requirements/tests.txt b/requirements/tests.txt
index fc49411f..fea8a4d2 100644
--- a/requirements/tests.txt
+++ b/requirements/tests.txt
@@ -18,9 +18,7 @@ pre-commit
 pyte>=0.8.0
 
 # types related
-# mypy==0.931
-git+git://github.com/python/mypy.git@9b3147701f054bf8ef42bd96e33153b05976a5e1
-# TODO: replace above with mypy==0.940 once its released
+mypy==0.940
 types-ujson
 
 # ensure tests run with the amalgamated (==production) xonsh
diff --git a/tests/test_builtins.py b/tests/test_builtins.py
index bf0c5b6b..ab5a2d1f 100644
--- a/tests/test_builtins.py
+++ b/tests/test_builtins.py
@@ -1,8 +1,10 @@
 """Tests the xonsh builtins."""
 import os
 import re
+import shutil
 import types
 from ast import AST, Expression, Interactive, Module
+from pathlib import Path
 
 import pytest
 
@@ -85,6 +87,41 @@ def test_repath_HOME_PATH_var_brace(home_env):
     assert exp == obs[0]
 
 
+# helper
+def check_repath(path, pattern):
+    base_testdir = Path("re_testdir")
+    testdir = base_testdir / path
+    testdir.mkdir(parents=True)
+    try:
+        obs = regexsearch(str(base_testdir / pattern))
+        assert [str(testdir)] == obs
+    finally:
+        shutil.rmtree(base_testdir)
+
+
+@skip_if_on_windows
+@pytest.mark.parametrize(
+    "path, pattern",
+    [
+        ("test*1/model", ".*/model"),
+        ("hello/test*1/model", "hello/.*/model"),
+    ],
+)
+def test_repath_containing_asterisk(path, pattern):
+    check_repath(path, pattern)
+
+
+@pytest.mark.parametrize(
+    "path, pattern",
+    [
+        ("test+a/model", ".*/model"),
+        ("hello/test+1/model", "hello/.*/model"),
+    ],
+)
+def test_repath_containing_plus_sign(path, pattern):
+    check_repath(path, pattern)
+
+
 def test_helper_int(home_env):
     helper(int, "int")