Skip to content

Commit

Permalink
Fix #21 WM_NAME decoding issue
Browse files Browse the repository at this point in the history
Issue where from_utf8 would error when presented with a latin-1 encoded
string, in the case of "Actualités"
  • Loading branch information
roosta committed Apr 22, 2021
1 parent aced01c commit c8cd14b
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
65 changes: 65 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ toml = "0.5.6"
serde = { version = "1.0.111", features = ["derive"] }
itertools = "0.9.0"
regex = "1"
encoding = "0.2"

[dependencies.i3ipc]
version = "0.10.1"
15 changes: 13 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ extern crate lazy_static;

extern crate toml;

extern crate encoding;
use encoding::{Encoding, DecoderTrap};
use encoding::all::ISO_8859_1;

pub mod config;
pub mod icons;
pub mod regex;
Expand Down Expand Up @@ -70,8 +74,15 @@ fn get_property(
);

let reply = cookie.get_reply()?;
let reply = std::str::from_utf8(reply.value())?.to_string();
Ok(reply)
if let Ok(s) = std::str::from_utf8(reply.value()) {
Ok(s.to_string())
} else {
let decoded = ISO_8859_1.decode(reply.value(), DecoderTrap::Strict);
match decoded {
Ok(s) => Ok(s),
Err(_) => Ok(String::new()),
}
}
}

/// Gets a window title, depends on wm_property config opt
Expand Down

0 comments on commit c8cd14b

Please sign in to comment.