Skip to content

Fix infinite recursion in expand_path when resolving paths with glob magic characters (#2036)#2038

Merged
martindurant merged 2 commits into
fsspec:masterfrom
Mahalaxmibejugam:fix-issue-2036
May 11, 2026
Merged

Fix infinite recursion in expand_path when resolving paths with glob magic characters (#2036)#2038
martindurant merged 2 commits into
fsspec:masterfrom
Mahalaxmibejugam:fix-issue-2036

Conversation

@Mahalaxmibejugam
Copy link
Copy Markdown
Contributor

@Mahalaxmibejugam Mahalaxmibejugam commented May 11, 2026

When calling expand_path(or the async _expand_path) with recursive=True on paths that resolve to filenames containing glob magic characters (such as [ or ?), the method would incorrectly treat these resolved paths as new glob patterns in the next recursive step. This led to either infinite recursion or unexpected FileNotFoundError when the characters were interpreted as character classes (e.g., file[1].txt searching for file1.txt).

To prevent this, assume_literal parameter is introduced to both expand_path and _expand_path:

  • By default, it is False.
  • When the method calls itself recursively on resolved paths (which we know are literals because they came from glob or find), it passes assume_literal=True.
  • This bypasses the has_magic check and ensures the paths are treated as literals, stopping the infinite recursion and preventing false glob interpretations.

Fixes #2036

@Mahalaxmibejugam Mahalaxmibejugam marked this pull request as ready for review May 11, 2026 10:46
@martindurant martindurant merged commit 85facaa into fsspec:master May 11, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

expand_path with recursive=True fails or enters infinite recursion on files with glob magic characters (e.g., *, [ , ])

2 participants