Skip to content

fix(parser): support directory paths with spaces in LIST command (#530) - #578

Merged
hannesdejager merged 1 commit into
Cloudinvoke:masterfrom
snowyukitty:fix/list-paths-with-spaces
Oct 25, 2026
Merged

hannesdejager merged 1 commit into
Cloudinvoke:masterfrom
snowyukitty:fix/list-paths-with-spaces

Conversation

@snowyukitty

Copy link
Copy Markdown
Contributor

Summary

Fixes #530.

When parsing the FTP LIST command with an argument containing spaces (such as LIST path with spaces), the parser previously performed a .split(|&b| b == b' ') and took .next(), causing the path to be truncated after the first space (resulting in path: Some("path")).

Changes

  1. src/server/controlchan/line_parser/parser.rs:
    • Updated LIST parameter parsing to iteratively strip leading hyphen-prefixed option flags (e.g. -la, -x) and support the -- option delimiter.
    • Preserved the entire remaining path string with embedded spaces intact.
  2. src/server/controlchan/line_parser/tests.rs:
    • Added unit test cases for LIST covering paths with spaces, multiple option flags, wildcard patterns, leading dashes with --, and whitespace-only input.
  3. tests/list.rs:
    • Added an end-to-end integration test creating a directory hierarchy with spaces (test_list_dir_spaces/sub folder/nested_target) and verifying that LIST test_list_dir_spaces/sub folder successfully returns the nested entries over the data channel.
  4. Cargo.toml:
    • Fixed workspace relative path for unftp-sbe-fs dev-dependency.

Verification

  • Passed all 69 unit tests and 26 doctests (cargo test).
  • Passed integration test suite including tests/list.rs.
  • Verified clean cargo clippy --all-targets --all-features and cargo fmt --check.

…udinvoke#530)

Fix LIST command path parsing when listing directories containing spaces in their names. Previously, split(' ') followed by .next() truncated any path after the first space. Now leading hyphen-prefixed option flags and the '--' option delimiter are stripped while preserving the remainder path string intact.

Fixes Cloudinvoke#530.
.map(|s| String::from_utf8_lossy(s).to_string())
.next();
let line_str = String::from_utf8_lossy(&line);
let mut remaining = line_str.trim_start();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for fixing this and adding the integration test! This resolves the reported issue with spaces in directory names.

I noticed one edge case: trim_start() also removes tabs and Unicode whitespace that can legitimately be part of a pathname. Leading ASCII spaces can matter too, so once option parsing ends, we should preserve the remaining pathname unchanged. I checked vsftpd’s implementation, which likewise preserves that remainder without trimming.

I’ll merge this as-is and handle that adjustment and the additional regression tests in a follow-up. No further changes needed from your side—thanks for the contribution!

@hannesdejager
hannesdejager merged commit 7142d6c into Cloudinvoke:master Oct 25, 2026
hannesdejager added a commit that referenced this pull request Oct 25, 2026
The fix for paths containing spaces in #578 also trimmed leading
whitespace. Tabs, Unicode spaces, and additional ASCII spaces can be
part of a pathname, so trimming can select a different directory.

Consume only the separating space after each leading option and keep
the pathname intact, including after the end-of-options delimiter.
Cover whitespace and encoded carriage returns in parser tests, and
exercise supported filenames over real control and data connections.
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.

Error when listing directories containing spaces in their names

2 participants