Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sxyazi
Copy link
Owner

@sxyazi sxyazi commented Oct 28, 2025

Prepare for #611

@sxyazi sxyazi requested a review from Copilot October 28, 2025 10:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR extends invalid UTF-8 support to command argument values for ya emit and ya emit-to commands. The implementation allows these CLI commands to accept byte sequences that aren't valid UTF-8 strings, while ensuring argument keys remain valid UTF-8.

Key changes:

  • Modified argument parsing to work with OsString instead of String, enabling invalid UTF-8 byte sequences as values
  • Added From trait implementations for Vec<u8> and &[u8] to automatically convert to Data::String or Data::Bytes
  • Updated CLI argument types from Vec<String> to Vec<OsString> for emit commands

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
yazi-shared/src/event/cmd.rs Refactored parse_args to accept generic iterators over OsString, parsing argument keys as UTF-8 while allowing values to be invalid UTF-8 bytes
yazi-shared/src/data/data.rs Added From trait implementations for byte slices that attempt UTF-8 conversion, falling back to Data::Bytes for invalid sequences
yazi-cli/src/args.rs Changed args field type from Vec<String> to Vec<OsString> in CommandEmit and CommandEmitTo structs
CHANGELOG.md Updated documentation references and added PR reference [#3290] to invalid UTF-8 support entry

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Data::Boolean(true)
let mut parts = arg.splitn(2, |&b| b == b'=');
let Some(Ok(key)) = parts.next().map(str::from_utf8) else {
bail!("argument key must be valid UTF-8: {arg:?}");
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

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

The error message shows {arg:?} but arg is a &[u8] after strip_prefix. This will display the raw byte array format instead of attempting to show what the invalid UTF-8 sequence might look like. Consider using String::from_utf8_lossy(arg) in the error message to provide more readable output.

Suggested change
bail!("argument key must be valid UTF-8: {arg:?}");
bail!("argument key must be valid UTF-8: {}", String::from_utf8_lossy(arg));

Copilot uses AI. Check for mistakes.
@sxyazi sxyazi merged commit 69bb4e0 into main Oct 28, 2025
6 checks passed
@sxyazi sxyazi deleted the pr-cdf3582d branch October 28, 2025 10:21
sxyazi added a commit that referenced this pull request Oct 28, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 28, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants