Skip to content

fix(alias): use POSIX shell word splitting for alias expansion#509

Merged
platinummonkey merged 1 commit into
DataDog:mainfrom
lognarly:fix/alias-shell-word-splitting
May 15, 2026
Merged

fix(alias): use POSIX shell word splitting for alias expansion#509
platinummonkey merged 1 commit into
DataDog:mainfrom
lognarly:fix/alias-shell-word-splitting

Conversation

@lognarly
Copy link
Copy Markdown
Contributor

Summary

Replaces split_whitespace() with shell_words::split() in alias expansion so that quoted strings (e.g. --query "SELECT COUNT(*) FROM dd.hosts") are preserved as a single token rather than split on interior whitespace, enabling DDSQL aliases with SQL queries to execute correctly.

Changes

  • Added shell-words = "1" to Cargo.toml (Cargo.toml)
  • Replaced split_whitespace() with shell_words::split() in apply_expansion (src/commands/alias.rs:92)
  • Added silent fallback to original args when alias value has an unclosed quote (src/commands/alias.rs:94)
  • Added test_apply_expansion_preserves_quoted_spaces to verify single-line quoted SQL queries expand correctly (src/commands/alias.rs)
  • Added test_apply_expansion_preserves_multiline_quoted_query to verify multiline YAML block scalar queries expand correctly (src/commands/alias.rs)
  • Added test_apply_expansion_unclosed_quote_returns_unchanged to verify malformed aliases fall back safely (src/commands/alias.rs)

Testing

  • All 13 alias tests pass
  • Verified locally against existing aliases.yaml with DDSQL queries using |- block scalar formatting
  • cargo clippy -- -D warnings clean, cargo fmt --check clean

Related Issues

N/A


🤖 Generated with Claude Code

Replace split_whitespace() with shell_words::split() so that quoted
strings in alias values (e.g. --query "SELECT ...") are preserved as
a single token rather than split on interior whitespace.

- Add shell-words crate to Cargo.toml
- Replace split_whitespace() in apply_expansion with shell_words::split()
- Fall back to original args unchanged on malformed aliases (unclosed quotes)
- Add tests for quoted spaces, multiline quoted queries, and unclosed quote fallback

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@lognarly lognarly requested a review from a team as a code owner May 15, 2026 14:39
@platinummonkey platinummonkey merged commit 5710fd2 into DataDog:main May 15, 2026
6 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.

2 participants