Skip to content

Shell parser: Handle I/O redirects, here-documents, and compound commands#48635

Merged
rtfeldman merged 2 commits intomainfrom
pr/shell-parser-redirects
Feb 6, 2026
Merged

Shell parser: Handle I/O redirects, here-documents, and compound commands#48635
rtfeldman merged 2 commits intomainfrom
pr/shell-parser-redirects

Conversation

@rtfeldman
Copy link
Contributor

This PR improves the shell command parser to correctly handle I/O redirects, here-documents, and compound command constructs. Previously, commands hidden inside redirect targets, here-document bodies, or function definition redirects could go undetected by the permission system.

Changes

  • Redirect handling: Capture I/O redirects on simple commands, compound commands (if/while/for/case/subshells/brace groups), and function definitions
  • Nested command extraction: Extract commands from redirect file targets (e.g. > $(dangerous_cmd)) and here-document bodies
  • Bare redirect rejection: Return None for bare redirects with no command name (e.g. > /etc/passwd), which forces confirmation
  • Compound command redirects: Apply redirects on compound commands to their inner body commands
  • Fail-closed error handling: extract_commands_from_word and normalize_word_piece_into now return None on parse failures instead of silently succeeding
  • Test coverage: Extensive tests for quoted redirect targets, no-space redirects, clobber operators, fd-to-fd redirects, pipe+redirect combinations, function definition redirects, and more

Release Notes:

  • Improved shell command parsing to correctly detect commands hidden in I/O redirects, here-documents, and compound command constructs.

…ands

- Capture I/O redirects on simple commands, compound commands, and function definitions
- Extract nested commands from redirect file targets (e.g. > $(cmd))
- Extract command substitutions from here-document bodies
- Return None for bare redirects with no command name
- Apply compound command redirects to inner body commands
- Propagate failures from nested command substitution parsing
- normalize_word_piece_into returns None on invalid source indices
- extract_commands_from_word fails closed on word parse error
- Extensive test coverage for redirect edge cases
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 6, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Feb 6, 2026
@maxdeviant maxdeviant changed the title Shell parser: handle I/O redirects, here-documents, and compound commands Shell parser: Handle I/O redirects, here-documents, and compound commands Feb 6, 2026
@rtfeldman rtfeldman marked this pull request as ready for review February 6, 2026 22:32
@rtfeldman rtfeldman merged commit 73d10cb into main Feb 6, 2026
27 checks passed
@rtfeldman rtfeldman deleted the pr/shell-parser-redirects branch February 6, 2026 22:32
naaiyy added a commit to Glass-HQ/Glass that referenced this pull request Feb 16, 2026
Key changes:
- LSP folding ranges support (zed-industries#48611) - textDocument/foldingRange with custom fold text
- LSP refactoring (zed-industries#48604) - extracted document_colors, code_lens, folding_ranges into modules
- Crate graph restructuring (zed-industries#48602) - terminal moved closer to editor
- Side-by-side diff searching (zed-industries#48539) and OpenExcerpts for LHS (zed-industries#48438)
- SplittableEditor: sync custom blocks between RHS/LHS (zed-industries#48575)
- Thinking effort for Zed/OpenAI providers (zed-industries#48545, zed-industries#48605)
- Agent default_model.enable_thinking setting (zed-industries#48536)
- Configurable LSP timeout setting (zed-industries#44745)
- PaneSearchBarCallbacks global (search bar setup extracted from vim)
- Settings migrations for nested platform/channel/profile keys (zed-industries#48550)
- Shell parser: I/O redirects, here-documents, compound commands (zed-industries#48635)
- Hardened tool authorization: sensitive settings, deferred ops (zed-industries#48641)
- rm security bypass fixes (zed-industries#48640, zed-industries#48647)
- MCP tool name parsing fix: newline delimiter (zed-industries#48636)
- Canonicalize --user-data-dir path (zed-industries#48470)
- Fix text_threads_dir XDG spec compliance (zed-industries#45771)
- Buffer font for folds (zed-industries#48652)
- Multibuffer toolbar layout shift fix (zed-industries#48472)
- Editor: tabs bitmask syncing (zed-industries#48366)

Conflict resolution:
- collab tests: deleted (collab removed)
- util/archive.rs, util/shell.rs: deleted (extracted to Obsydian)
- copilot_ui/sign_in.rs: kept native_button style
- editor_tests.rs: merged imports (kept MoveItemToPaneInDirection, added ViewId/FollowEvent)
- lsp_store.rs: took upstream refactored imports, added FoldingRangeData, removed collab imports
- main.rs: added PaneSearchBarCallbacks, removed vim::init

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant