zonyitoo / rust-ini

INI file parser in Rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Line with single quote causes parsing issues

qwertychouskie opened this issue · comments

Take for example, this file:

[Desktop Entry]
Version=1.0
Name[af]=Padkaart
Name[an]=Mapas
Name[ar]=الخرائط
Name=Maps
Comment[af]='n Eenvoudige padkaart-toepassing
Comment[an]=Una aplicación simpla de mapas
Comment[ar]=تطبيق خرائط بسيط
Comment=A simple maps application
Exec=/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=gapplication --file-forwarding org.gnome.Maps launch org.gnome.Maps @@u %U @@
Icon=org.gnome.Maps
Terminal=false
Type=Application
StartupNotify=true
Categories=GNOME;GTK;Utility;

Because of the line Comment[af]='n Eenvoudige padkaart-toepassing, if I let command = match section.get("Exec") it will return None. Setting option.enabled_quote to true or false doesn't seem to make a difference.

commented

rust-ini/src/lib.rs

Lines 1362 to 1370 in 13ed93d

Some('\'') if self.opt.enabled_quote => {
self.bump();
self.parse_str_until(&[Some('\'')], false).and_then(|s| {
self.bump(); // Eats the last '
// Parse until EOL
self.parse_str_until_eol(cfg!(feature = "inline-comment"))
.map(|x| s + &x)
})
}

Setting enabled_quote to false should work, emm....

You're right, for some reason it wasn't compiling the changed code after I updated it. Still, it would probably be a good idea to find a way to fail more gracefully when enabled_quote = true.

commented

I just ran a test with your case:

    #[test]
    fn issue113_string_no_quotes() {
        let input = "
[Desktop Entry]
Version=1.0
Name[af]=Padkaart
Name[an]=Mapas
Name[ar]=الخرائط
Name=Maps
Comment[af]='n Eenvoudige padkaart-toepassing
Comment[an]=Una aplicación simpla de mapas
Comment[ar]=تطبيق خرائط بسيط
Comment=A simple maps application
Exec=/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=gapplication --file-forwarding org.gnome.Maps launch org.gnome.Maps @@u %U @@
Icon=org.gnome.Maps
Terminal=false
Type=Application
StartupNotify=true
Categories=GNOME;GTK;Utility;
";

        let ini = Ini::load_from_str_opt(input,
                                         ParseOption { enabled_quote: false,
                                                       ..Default::default() }).unwrap();
        assert_eq!(ini.get_from(Some("Desktop Entry"), "Exec"), Some("/usr/bin/flatpak run --branch=stable --arch=x86_64 --command=gapplication --file-forwarding org.gnome.Maps launch org.gnome.Maps @@u %U @@"));
    }

which worked perfectly as expected:

running 1 test
test test::issue113_string_no_quotes ... ok