Skip to content

Commit

Permalink
fix wildcards with path sequence
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Mandic <mandic00@live.com>
  • Loading branch information
vladmandic committed Jan 31, 2025
1 parent 7d2d4ff commit 780ceb0
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions modules/styles.py
Original file line number Diff line number Diff line change
@@ -44,13 +44,13 @@ def apply_styles_to_prompt(prompt, styles):

def apply_file_wildcards(prompt, replaced = [], not_found = [], recursion=0, seed=-1):
def check_wildcard_files(prompt, wildcard, files, file_only=True):
trimmed = wildcard.replace('\\', '').replace('/', '').strip().lower()
trimmed = wildcard.replace('\\', os.path.sep).strip().lower()
for file in files:
if file_only:
paths = [os.path.splitext(os.path.basename(file).lower())[0]]
paths = [os.path.splitext(file)[0].lower(), os.path.splitext(os.path.basename(file).lower())[0]] # fullname and basename
else:
paths = [os.path.splitext(p.lower())[0] for p in os.path.normpath(file).split(os.path.sep)]
if trimmed in paths:
paths = [os.path.splitext(p.lower())[0] for p in os.path.normpath(file).split(os.path.sep)] # every path component
if (trimmed in paths) or (os.path.sep in trimmed and trimmed in paths[0]):
try:
with open(file, 'r', encoding='utf-8') as f:
lines = f.readlines()
@@ -77,6 +77,8 @@ def check_wildcard_files(prompt, wildcard, files, file_only=True):
if len(matches) == 0:
return prompt, replaced, not_found
files = list(files_cache.list_files(shared.opts.wildcards_dir, ext_filter=[".txt"], recursive=True))
if len(files) == 0:
return prompt, replaced, not_found
for wildcard in matches:
prompt, found = check_wildcard_files(prompt, wildcard, files)
if found and wildcard in not_found:

0 comments on commit 780ceb0

Please # to comment.