-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Use try_from_bytes in handle_file_urls #7652
Use try_from_bytes in handle_file_urls #7652
Conversation
crates/zed/src/open_listener.rs
Outdated
@@ -131,7 +129,7 @@ impl OpenListener { | |||
.flat_map(|url| url.strip_prefix("file://")) | |||
.map(|url| { | |||
let decoded = urlencoding::decode_binary(url.as_bytes()); | |||
PathBuf::from(OsStr::from_bytes(decoded.as_ref())) | |||
PathBuf::try_from_bytes(decoded.as_ref()).unwrap() |
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.
Note: try_from_bytes
always returns Ok
on [cfg(unix)]
.
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.
Because we don't control the input to this method, we should not panic if the bytes are invalid, but just ignore them. I think the following would be better:
PathBuf::try_from_bytes(decoded.as_ref()).unwrap() | |
.flat_map(|url| { | |
let decoded = urlencoding::decode_binary(url.as_bytes()); | |
PathBuf::try_from_bytes(decoded.as_ref()).log_err() | |
}) |
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.
I fixed this
I have no objections from merging that in if the reviewer finds it appropriate, but strongly urge you to consider adding Windows runners (GitHub seem to allow the standard ones: https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners/about-github-hosted-runners#using-a-github-hosted-runner so we can do smth. like #7581). I would not expect the code to 100% compile under Windows now, but some of the crates may be already? |
@SomeoneToIgnore I think we've decided to wait on any big windows stuff until post linux; so let's not worry about CI. @kazatsuyu Thanks for working on this. In general we should avoid unwrap'ing on errors, left a suggestion in line, but otherwise good to go. |
Thanks! |
Reduce build error on Windows.
Release Notes: