Skip to content

Commit

Permalink
Merge pull request #72 from Anomalocaridid/fix-discussion-bugs
Browse files Browse the repository at this point in the history
fix: bugs mentioned in discussions #68 and #47
  • Loading branch information
Anomalocaridid authored Jul 31, 2024
2 parents 65797a7 + 5b07276 commit 8f6c51c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/common/desktop_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ impl DesktopEntry {

// If the entry expects a terminal (emulator), but this process is not running in one, we
// launch a new one.
if self.terminal && config.terminal_output {
// TODO: make regression test (currently infeasible with terminal method's reliance on system state)
if self.terminal && !config.terminal_output {
let term_cmd = config.terminal(selector, use_selector)?;
exec = shlex::split(&term_cmd)
.ok_or_else(|| Error::from(ErrorKind::BadCmd(term_cmd)))?
Expand Down
23 changes: 18 additions & 5 deletions src/common/mime_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,33 @@ impl TryFrom<&Path> for MimeType {
guess.file_name(&path.to_string_lossy());

let mime = if let Some(mime) =
mime_to_option(&db, guess.guess().mime_type().clone())
mime_to_option(&db, guess.guess().mime_type().clone(), true)
{
mime
} else {
mime_to_option(&db, guess.path(path).guess().mime_type().clone())
.ok_or_else(|| ErrorKind::Ambiguous(path.to_owned()))?
mime_to_option(
&db,
guess.path(path).guess().mime_type().clone(),
false,
)
.ok_or_else(|| ErrorKind::Ambiguous(path.to_owned()))?
};

Ok(Self(mime))
}
}

/// Tests if a given mime is "acceptable" and returns None otherwise
fn mime_to_option(db: &xdg_mime::SharedMimeInfo, mime: Mime) -> Option<Mime> {
fn mime_to_option(
db: &xdg_mime::SharedMimeInfo,
mime: Mime,
discard_zerosize: bool,
) -> Option<Mime> {
let application_zerosize: Mime = "application/x-zerosize".parse().ok()?;

if mime == mime::APPLICATION_OCTET_STREAM
|| db.mime_type_equal(&mime, &application_zerosize)
|| (db.mime_type_equal(&mime, &application_zerosize)
&& discard_zerosize)
{
None
} else {
Expand Down Expand Up @@ -138,6 +147,10 @@ mod tests {
MimeType::try_from(Path::new("./tests/no_html_tags.html"))?.0,
"text/html"
);
assert_eq!(
MimeType::try_from(Path::new("./tests/empty"))?.0,
"application/x-zerosize"
);

Ok(())
}
Expand Down
Empty file added tests/empty
Empty file.

0 comments on commit 8f6c51c

Please sign in to comment.