Skip to content

Commit

Permalink
🪲 fix glob crash/wrong results on meta-characters
Browse files Browse the repository at this point in the history
Escape meta-characters * ? [ ] by [bracketing them]

Fixes: kek91#22
  • Loading branch information
eugenesvk committed Aug 14, 2021
1 parent 79c453d commit 07727c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file
## [Unreleased]
[ Unreleased]: https://github.com/kek91/StatusBarExtended/compare/v0.4.1...HEAD

- __Fixed__
+ :beetle: glob meta-characters `[` `]` `*` `?` in paths (e.g. `[A--_B]`) crash glob or lead to wrong results

## [v0.4.1 — 13.08.2021]
[ v0.4.1 — 13.08.2021]: https://github.com/kek91/StatusBarExtended/releases/tag/v0.4.1
- __Added__
Expand Down
8 changes: 5 additions & 3 deletions statusbarextended/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from fman.fs import is_dir, query
from core.commands.util import is_hidden # works on file_paths, not urls
import glob
import re
from byteconverter import ByteConverter
#from PyQt5.QtWidgets import QApplication
import statusbarextended_config as SBEcfg
Expand All @@ -27,15 +28,16 @@ def refresh(self, cfg):
cfg['SymbolHiddenF'][1]
cur_dir_url = self.pane.get_path()
current_dir = as_path(cur_dir_url)
current_dir_gnorm= re.sub(r'(?P<bracket>\[|\]|\?|\*)',r'[\g<bracket>]',current_dir) # bracket the brackets, asterisks and question marks in paths to match them literaly instead of treating them as special globl characters
dir_folders = 0
dir_files = 0
dir_filesize = 0
dir_files_in_dir = glob.glob(current_dir + "/*")
dir_files_in_dir = glob.glob(current_dir_gnorm + "/*")
if PLATFORM == 'Windows' and not cfg['HideDotfile']:
# .dotfiles=regular (always shown unless have a 'hidden' attr)
dir_files_in_dir += glob.glob(current_dir + "/.*")
dir_files_in_dir += glob.glob(current_dir_gnorm + "/.*")
elif cfg_show_hidden_files: # .dotfile=hidden (internal option shows)
dir_files_in_dir += glob.glob(current_dir + "/.*")
dir_files_in_dir += glob.glob(current_dir_gnorm + "/.*")
f_url = ""
aboveMax = False

Expand Down

0 comments on commit 07727c0

Please sign in to comment.