Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip over tab characters before comment delimiter #98

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1163,20 +1163,20 @@ impl<'a> Parser<'a> {
return self.error(format!("expecting \"{:?}\" but found EOF.", endpoint));
}
#[cfg(feature = "inline-comment")]
Some(' ') if check_inline_comment => {
Some(space) if check_inline_comment && (space == ' ' || space == '\t') => {
self.bump();

match self.ch {
Some('#') | Some(';') => {
// [space]#, [space]; starts an inline comment
break;
}
Some(c) => {
result.push(' ');
result.push(c);
Some(_) => {
result.push(space);
continue;
}
None => {
result.push(' ');
result.push(space);
}
}
}
Expand Down Expand Up @@ -1527,12 +1527,18 @@ gender = mail ; abdddd
name = hello # abcdefg
gender = mail ; abdddd
address = web#url ;# eeeeee
phone = 01234 # tab before comment
phone2 = 56789 # tab + space before comment
phone3 = 43210 # space + tab before comment
";
let ini = Ini::load_from_str(input).unwrap();
println!("{:?}", ini.section(Some("section name")));
assert_eq!(ini.get_from(Some("section name"), "name").unwrap(), "hello");
assert_eq!(ini.get_from(Some("section name"), "gender").unwrap(), "mail");
assert_eq!(ini.get_from(Some("section name"), "address").unwrap(), "web#url");
assert_eq!(ini.get_from(Some("section name"), "phone").unwrap(), "01234");
assert_eq!(ini.get_from(Some("section name"), "phone2").unwrap(), "56789");
assert_eq!(ini.get_from(Some("section name"), "phone3").unwrap(), "43210");
}

#[test]
Expand Down