Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape all shell special characters #23

Merged
merged 1 commit into from
Nov 25, 2024
Merged

Conversation

thaliaarchi
Copy link
Collaborator

Allows only characters which don't require quoting. I realized I was thinking about only the characters used in what's conceptually a string, but there's many more. I consulted https://stackoverflow.com/questions/15783701/which-characters-need-to-be-escaped-when-using-bash/27817504#27817504, which derives its list from what needs escaping with ${var@Q}.

def sh_escape:
if . == "" or test("['\" $\n\\\\()]") then
if . == "" or test("[^[A-Za-z0-9%+\\-./:=@_]]") then
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 yeap that feels safer. that stackoverflow response is quite impressive!

@wader wader merged commit e35c266 into wader:master Nov 25, 2024
3 checks passed
@wader
Copy link
Owner

wader commented Nov 25, 2024

Turned out it didn't work as intended and took me embarrassingly long time to see what was wrong :) fixed in 482c422

@thaliaarchi
Copy link
Collaborator Author

Oops. Sorry, I didn't test it locally since it looked right. I assumed it would be caught with CI

@wader
Copy link
Owner

wader commented Nov 26, 2024

No worries 👍 sadly the current --run-tests-tests does not exercise the cli much. I've thought about improving it somehow, maybe something similar to jq's shtest stuff? or extend the .test-format to be able to run cli commands and assert on expected stdout/stderr output, a bit like fq's tests? 🤔

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.

2 participants