Skip to content

Commit

Permalink
Handle forward slashes in chan names in logger
Browse files Browse the repository at this point in the history
Fixes #214
  • Loading branch information
osa1 committed Jun 21, 2020
1 parent d3374c3 commit 5a87269
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
extend input field vertically. (#101)
- A few crashes when connecting to some IRC servers fixed. tiny is now more
resilient to non-standard-conforming messages from servers. (#211)
- Fixed a bug in logger when the channel name contains forward slash character.
(#214)

[rustls]: https://github.com/ctz/rustls
[native-tls]: https://github.com/sfackler/rust-native-tls
Expand Down
12 changes: 10 additions & 2 deletions libtiny_logger/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,14 @@ macro_rules! report_io_err {
};
}

// '/' is valid in channel names but we can't use it in file names, so we replace it with '-'.
// According to RFC 2812 nick names can't contain '/', but we still use this in nicks just to be
// safe. Other special characters mentioned in the RFC ("[]\`^{|}") can be used in file names so we
// don't replace those.
fn replace_forward_slash(path: &str) -> String {
path.replace('/', "-")
}

// This is a macro to avoid borrow checking issues
macro_rules! try_open_log_file {
( $report_err:expr, $path:expr ) => {
Expand Down Expand Up @@ -169,7 +177,7 @@ impl LoggerInner {
}
Some(server) => {
let mut path = self.log_dir.clone();
path.push(&format!("{}_{}.txt", serv, chan));
path.push(&format!("{}_{}.txt", serv, replace_forward_slash(chan)));
debug!("Trying to open log file: {:?}", path);
if let Some(mut fd) = try_open_log_file!(self.report_err, &path) {
report_io_err!(self.report_err, print_header(&mut fd));
Expand Down Expand Up @@ -336,7 +344,7 @@ impl LoggerInner {
// We don't have a `new_user_tab` trait method so user log files
// are created here
let mut path = self.log_dir.clone();
path.push(&format!("{}_{}.txt", serv, nick));
path.push(&format!("{}_{}.txt", serv, replace_forward_slash(nick)));
debug!("Trying to open log file: {:?}", path);
if let Some(mut fd) = try_open_log_file!(self.report_err, &path) {
report_io_err!(self.report_err, print_header(&mut fd));
Expand Down

0 comments on commit 5a87269

Please sign in to comment.