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

Line with single quote causes parsing issues #113

Open
qwertychouskie opened this issue Aug 23, 2023 · 3 comments
Open

Line with single quote causes parsing issues #113

qwertychouskie opened this issue Aug 23, 2023 · 3 comments

Comments

@qwertychouskie
Copy link

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.

@zonyitoo
Copy link
Owner

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....

@qwertychouskie
Copy link
Author

qwertychouskie commented Aug 24, 2023

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.

@zonyitoo
Copy link
Owner

zonyitoo commented Aug 26, 2023

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

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

No branches or pull requests

2 participants