fix(prelude): unsuppress glob in os.dirs by escaping shell metachars#15
Merged
Sunrisepeak merged 1 commit intomainfrom May 5, 2026
Merged
fix(prelude): unsuppress glob in os.dirs by escaping shell metachars#15Sunrisepeak merged 1 commit intomainfrom
Sunrisepeak merged 1 commit intomainfrom
Conversation
`os.dirs(pattern)` used `ls -d "<pattern>" 2>/dev/null` on POSIX. Wrapping the pattern in double quotes makes the shell skip glob expansion entirely — `ls -d "/tmp/x/cuda_v*"` looks for a literal file named `cuda_v*` and returns nothing. Reproduced by upstream user. Fix: replace the all-quote approach with a per-character backslash escape that preserves glob meta (`* ? [ ] ~`) while still quoting whitespace, $, backticks, and shell redirects/control chars. Now `ls -d` receives an unquoted pattern that the shell expands as expected, and paths with spaces still survive. Windows branch unchanged: cmd.exe `dir` does its own pattern matching on the argument, so the existing quoted form there is correct.
Sunrisepeak
added a commit
that referenced
this pull request
May 5, 2026
The cppm is auto-generated by xmake `before_build` from src/lua-stdlib/* but also tracked in git as a snapshot. PR #15 updated prelude.lua but left the committed snapshot stale — builds work because xmake regenerates at build time, but the diff is misleading. Re-run the embed and commit the result so HEAD matches what a fresh build would produce.
This was referenced May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
os.dirs(pattern)shells out tols -d "<pattern>" 2>/dev/nullon POSIX. Wrapping the pattern in double quotes makes the shell skip glob expansion entirely —ls -d "/tmp/x/cuda_v*"looks for a literal file namedcuda_v*and returns nothing.Reproduced upstream:
Any
xpkgpackage usingos.dirs("…/v*")to enumerate installed versions silently returned an empty list.Fix
Replace the all-quote approach with a per-character backslash escape that preserves glob meta (
* ? [ ] ~) while still escaping whitespace,$, backticks, quotes, and shell redirect/control chars.ls -dthen receives an unquoted pattern that the shell expands, and paths with spaces still survive.Windows branch unchanged:
cmd.exe's built-indirdoes its own pattern matching on the argument, so the existing quoted form there is correct.Test plan
xmake buildcleanxpkg_executor_testcases pass/tmp/x/cuda_v*, escaped space/tmp/x\ space/cuda_v*still works