Skip to content

Commit

Permalink
Merge pull request #854 from Amulet-Team/fix-glob
Browse files Browse the repository at this point in the history
Fixed glob
  • Loading branch information
gentlegiantJGC authored Dec 21, 2022
2 parents 641afed + d7eedc1 commit e417c6b
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Amulet.spec
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ for module_path in (
MINECRAFT_MODEL_READER,
):
for path in glob.glob(
os.path.join(os.path.abspath(module_path), "**", "*.py"), recursive=True
os.path.join(glob.escape(os.path.abspath(module_path)), "**", "*.py"), recursive=True
):
if path not in added_source:
rel_path: str = os.path.relpath(path, os.path.dirname(module_path))
Expand Down
2 changes: 1 addition & 1 deletion amulet_map_editor/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _init_log():
# set up handlers
os.makedirs(logs_path, exist_ok=True)
# remove all log files older than a week
for path in glob.glob(os.path.join(logs_path, "*.log")):
for path in glob.glob(os.path.join(glob.escape(logs_path), "*.log")):
if (
os.path.isfile(path)
and os.path.getmtime(path) < time.time() - 3600 * 24 * 7
Expand Down
4 changes: 2 additions & 2 deletions amulet_map_editor/api/lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def get_languages() -> List[str]:
"""Get a list of all supported language codes."""
langs = set()
for d in _lang_dirs:
for l in glob.glob(os.path.join(d, "*.lang")):
for l in glob.glob(os.path.join(glob.escape(d), "*.lang")):
langs.add(os.path.basename(l)[:-5])
return sorted(langs)

Expand Down Expand Up @@ -124,7 +124,7 @@ def _find_langs(path: str) -> Tuple[Optional[str], Optional[str], Optional[str]]
"""Find the default, language specific and region specific lang paths."""
langs = {
parse_language_id(os.path.basename(lpath)[:-5]): lpath
for lpath in glob.glob(os.path.join(path, "*.lang"))
for lpath in glob.glob(os.path.join(glob.escape(path), "*.lang"))
}

default_key = parse_language_id(_default_language)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def setup(self) -> Generator[float, None, None]:
os.stat(path).st_mtime
for pack in self._resource_pack.pack_paths
for path in glob.glob(
os.path.join(pack, "**", "*.*"), recursive=True
os.path.join(glob.escape(pack), "**", "*.*"), recursive=True
)
),
default=0,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lang.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class LangTestCase(unittest.TestCase):
def test_lang(self):
for lang_dir in lang_dirs():
for lang_path in glob.glob(os.path.join(lang_dir, "*")):
for lang_path in glob.glob(os.path.join(glob.escape(lang_dir), "*")):
self.assertTrue(
lang_path.endswith(".lang"),
f'{lang_path} does not end with ".lang".',
Expand Down

0 comments on commit e417c6b

Please sign in to comment.