-
-
Notifications
You must be signed in to change notification settings - Fork 72
Fix elevated command parsing #425
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
base: master
Are you sure you want to change the base?
Conversation
WalkthroughReplaces whitespace-based tokenization with shlex parsing when constructing elevated commands; adds Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller
participant CommandBuilder
participant Shlex as shlex::split
participant Process as std::process::Command
Caller->>CommandBuilder: build_elevated(cmdline)
CommandBuilder->>Shlex: shlex::split(cmdline)
alt parse succeeds
Shlex-->>CommandBuilder: Vec<String> parts
CommandBuilder->>Process: new(&parts[0])
CommandBuilder->>Process: args(parts[1..].iter().map(|s| s.as_str()))
Process-->>Caller: Command ready
else parse fails
Shlex-->>CommandBuilder: None / Err
CommandBuilder-->>Caller: error("Failed to parse sudo command")
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (3)
CHANGELOG.md (1)
20-21: Grammar/typo: “supports” and “column”.
- Change “now support” → “now supports”.
- Fix “coloumn” → “column”.
Apply this diff:
- - `nh os info` now support `--fields` to select which field(s) to display; - also add a per-generation "Closure Size" coloumn. + - `nh os info` now supports `--fields` to select which field(s) to display; + also add a per-generation "Closure Size" column.src/commands.rs (2)
428-431: Non‑UTF‑8 args are lost.Even if keeping shlex, building from Strings drops non‑UTF‑8. Prefer args_os() end‑to‑end.
973-978: Test is fine; small robustness nit.Parsing via shlex is okay here, but this test still depends on the formatting of to_cmdline_lossy. If you adopt direct Command construction, consider asserting presence of “-A”/“env”/assignments via a helper that builds argv rather than relying on a pretty-printed line.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (3)
CHANGELOG.md(1 hunks)Cargo.toml(1 hunks)src/commands.rs(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
- GitHub Check: Test NH on Darwin
- GitHub Check: Test NH on Linux
- GitHub Check: treewide-checks
- GitHub Check: Build NH on Linux
- GitHub Check: Build NH on Darwin
🔇 Additional comments (2)
CHANGELOG.md (1)
24-30: Changelog entry reads well; aligns with the fix.Accurately documents the switch to shlex-based parsing for elevated command construction.
Cargo.toml (1)
52-52: Do not move shlex to dev-dependencies — it's used at runtime.
ripgrep shows shlex:: calls in src/commands.rs (lines 417–419 and 974–976); keep shlex in [dependencies] or remove/replace those runtime usages.Likely an incorrect or invalid review comment.
|
I'm not exactly sure if I really want to introduce a crate for this? This should be doable with just the stdlib by parsing the command beforehand, but I'm talking based on what I remember from the top of my head. |
Yeah, it would be nice to avoid it. I will check if there's something. However, should more effort be put into this approach? I think it's best to focus on trying to decouple the logic of building a command from both |
|
Update: couldn't find anything in the standard library to avoid adding a crate. Please let me know if I missed something. |
Fixes #421 by changing how the elevated command is converted from
subproces::Exectostd::process::Command. It now uses shlex to correctly parse the command.Sanity Checking
nix fmtto format my Nix codecargo fmtto format my Rust codecargo clippyand fixed any new linter warnings.logic
description.
x86_64-linuxaarch64-linuxx86_64-darwinaarch64-darwinAdd a 👍 reaction to pull requests you find important.
Summary by CodeRabbit