fix: %F and %U field code handling

Fixes %F path arguments being ignored
This commit is contained in:
Michael Aaron Murphy 2026-04-29 21:52:11 +02:00
parent d775f3e5e8
commit 1fcd0dccc8
No known key found for this signature in database
GPG key ID: B2732D4240C9212C

View file

@ -49,42 +49,19 @@ pub fn exec_to_command(
} }
} }
Some('f') => { // %f and %u behave the same in a file manager.
if !field_code_used { Some('f' | 'u') if !field_code_used => {
// TODO: files on remote file systems should be copied to a temporary local file. // TODO: files on remote file systems should be copied to a temporary local file.
batch_process = true; batch_process = true;
field_code_used = true; field_code_used = true;
new_argument.push_str(path.as_bytes()); new_argument.push_str(path.as_bytes());
}
} }
Some('F') => { // %F and %U behave the same in a file manager.
if !field_code_used && new_argument.is_empty() { Some('F') | Some('U') if !field_code_used && new_argument.is_empty() => {
field_code_used = true; field_code_used = true;
for path in path_opt for path in path_opt.iter().map(AsRef::as_ref) {
.iter() args.push(BString::new(path.as_bytes().to_owned()));
.map(AsRef::as_ref)
.filter(|&path| from_file_or_dir(path).is_none())
{
args.push(BString::new(path.as_bytes().to_owned()));
}
}
}
Some('u') => {
if !field_code_used {
batch_process = true;
field_code_used = true;
new_argument.push_str(path.as_bytes());
}
}
Some('U') => {
if !field_code_used && new_argument.is_empty() {
field_code_used = true;
for path in path_opt.iter().map(AsRef::as_ref) {
args.push(BString::new(path.as_bytes().to_owned()));
}
} }
} }
@ -133,12 +110,6 @@ pub fn exec_to_command(
Some(commands) Some(commands)
} }
fn from_file_or_dir(path: impl AsRef<Path>) -> Option<url::Url> {
url::Url::from_file_path(&path)
.ok()
.or_else(|| url::Url::from_directory_path(&path).ok())
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct MimeApp { pub struct MimeApp {
pub id: String, pub id: String,
@ -490,33 +461,40 @@ mod tests {
#[test] #[test]
#[allow(non_snake_case)] #[allow(non_snake_case)]
fn one_path_F_field_code() { fn one_path_F_field_code() {
let exec = "/usr/bin/bar %F"; let exec = "/usr/bin/cosmic-term -w %F";
let paths = ["cat"]; let paths = ["/home/user"];
let commands = exec_to_command(exec, "one_path_F_field_code", None, &paths) let commands = exec_to_command(exec, "one_path_F_field_code", None, &paths)
.expect("Should parse valid exec"); .expect("Should parse valid exec");
assert_eq!(1, commands.len()); assert_eq!(1, commands.len());
let command = commands.first().unwrap(); let command = commands.first().unwrap();
let mut args = command.get_args();
assert_eq!("/usr/bin/bar", command.get_program().to_str().unwrap()); assert_eq!(
assert_eq!("cat", command.get_args().next().unwrap().to_str().unwrap()); "/usr/bin/cosmic-term",
command.get_program().to_str().unwrap()
);
assert_eq!("-w", args.next().unwrap().to_str().unwrap());
assert_eq!(paths[0], args.next().unwrap().to_str().unwrap());
} }
#[test] #[test]
fn one_path_u_field_code() { fn one_path_u_field_code() {
let exec = "/usr/bin/foobar %u"; let exec = "/usr/bin/cosmic-term -w %u";
let paths = ["/home/josh/krumpli"]; let paths = ["/home/user"];
let commands = exec_to_command(exec, "one_path_u_field_code", None, &paths) let commands = exec_to_command(exec, "one_path_u_field_code", None, &paths)
.expect("Should parse valid exec"); .expect("Should parse valid exec");
assert_eq!(1, commands.len()); assert_eq!(1, commands.len());
let command = commands.first().unwrap(); let command = commands.first().unwrap();
let mut args = command.get_args();
assert_eq!("/usr/bin/foobar", command.get_program().to_str().unwrap());
assert_eq!( assert_eq!(
*paths.first().unwrap(), "/usr/bin/cosmic-term",
command.get_args().next().unwrap().to_str().unwrap() command.get_program().to_str().unwrap()
); );
assert_eq!("-w", args.next().unwrap().to_str().unwrap());
assert_eq!(paths[0], args.next().unwrap().to_str().unwrap());
} }
#[test] #[test]