Skip to content

Commit

Permalink
[#64] EscapePolicy::Basics shouldn't escape \x08..=\xFF
Browse files Browse the repository at this point in the history
  • Loading branch information
zonyitoo committed Feb 18, 2020
1 parent 04294a9 commit 3714414
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rust-ini"
version = "0.15.1"
version = "0.15.2"
authors = ["Y. T. Chung <[email protected]>"]
description = "An Ini configuration file parsing library in Rust"
repository = "https://github.com/zonyitoo/rust-ini"
Expand Down
17 changes: 16 additions & 1 deletion src/ini.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ impl EscapePolicy {
/// per this policy or false if not.
pub fn should_escape(self, c: char) -> bool {
match c {
'\\' | '\x00'..='\x1f' | '\x7f'..='\u{00ff}' => self.escape_basics(),
// A single backslash, must be escaped
// ASCII control characters, U+0000 NUL..= U+001F UNIT SEPARATOR, or U+007F DELETE. The same as char::is_ascii_control()
'\\' | '\x00'..='\x1f' | '\x7f' => self.escape_basics(),
';' | '#' | '=' | ':' => self.escape_reserved(),
'\u{0080}'..='\u{FFFF}' => self.escape_unicode(),
_ => false,
Expand Down Expand Up @@ -213,6 +215,7 @@ impl LineSeparator {
}

/// Writing configuration
#[derive(Debug, Clone)]
pub struct WriteOption {
/// Policies about how to escape characters
pub escape_policy: EscapePolicy,
Expand Down Expand Up @@ -1732,4 +1735,16 @@ bar = f
let v = conf.get_from(Some(section), key).unwrap();
assert_eq!(v, new_value);
}

#[test]
fn fix_issue64() {
let input = format!("some-key=åäö{}", super::DEFAULT_LINE_SEPARATOR);

let conf = Ini::load_from_str(&input).unwrap();

let mut output = Vec::new();
conf.write_to_policy(&mut output, EscapePolicy::Basics).unwrap();

assert_eq!(input, String::from_utf8(output).unwrap());
}
}

0 comments on commit 3714414

Please sign in to comment.