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

EscapePolicy::Basics escapes unicode #64

Closed
johansigfrids opened this issue Feb 16, 2020 · 8 comments
Closed

EscapePolicy::Basics escapes unicode #64

johansigfrids opened this issue Feb 16, 2020 · 8 comments
Assignees
Labels

Comments

@johansigfrids
Copy link

It seems both EscapePolicy::Basics and EscapePolicy::BasicsUnicode escape non-ascii unicode characters. EscapePolicy::Nothing does not escape unicode, but doesn't escape anything else either.

For example, have a in.ini files with some unicode in it:

some-key=åäö

And a main.rs file which reads and writes the ini:

use ini::Ini;
use ini::ini::EscapePolicy;

fn main() {
    let ini = Ini::load_from_file("in.ini").unwrap();
    ini.write_to_file_policy("basics.ini", EscapePolicy::Basics).unwrap();
    ini.write_to_file_policy("basics_unicode.ini", EscapePolicy::BasicsUnicode).unwrap();
}

Both basics.ini and basics_unicode.ini end up the same:

some-key=\x00e5\x00e4\x00f6

I would have expected basics.ini to leave the unicode stuff as is.

@zonyitoo
Copy link
Owner

zonyitoo commented Feb 16, 2020

Because åäö are \u{e5}, \u{e4}, \u{f6}, which are in the range \x7f..=\u{00ff}, so they are controlled by escape_basics().

So if you want them to be printed as original, use EscapePolicy::Nothing.

@johansigfrids
Copy link
Author

If EscapePolicy::Basics escapes unicode, then what does EscapePolicy::BasicsUnicode do differently?

@zonyitoo
Copy link
Owner

I checked all commits related to this line of code, and it seems that it is bug introduced 4 years ago.

4 years ago @mitsuhiko added EscapePolicy and simply replaced the original escape match condition with a check escape_basics().

@zonyitoo zonyitoo added the bug label Feb 17, 2020
@zonyitoo zonyitoo self-assigned this Feb 17, 2020
@zonyitoo zonyitoo reopened this Feb 17, 2020
@zonyitoo zonyitoo reopened this Feb 17, 2020
@zonyitoo
Copy link
Owner

@johansigfrids Please verify if it this commit works in your case.

@johansigfrids
Copy link
Author

Yes! Now EscapePolicy::Basics does not escape the unicode, but EscapePolicy::BasicsUnicode does.

@zonyitoo
Copy link
Owner

Yes! Now EscapePolicy::Basics does not escape the unicode, but EscapePolicy::BasicsUnicode does.

It is expected, right?

If everything is ok, I am going to release a new version.

@johansigfrids
Copy link
Author

Yes, it now works the way I would expect it to.

@zonyitoo
Copy link
Owner

Released in v0.15.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants