zonyitoo / rust-ini

INI file parser in Rust
MIT License
305 stars 79 forks source link

ParseError "expecting \"[Some('\\'')]\" but found EOF." #136

Closed AllanDaemon closed 2 months ago

AllanDaemon commented 2 months ago

When trying to parse XDG Ini files in Ubuntu, a certain file that seems to comply with INI fails to parse with a mysterious error.

For parsing, I'm using the code:

let ini = Ini::load_from_file(path).unwrap();

From the 457 .desktop files provided by Debian packages installed in my system, all of them parses successfully, but the following one fails to parse with the following error:

called `Result::unwrap()` on an `Err` value: Parse(ParseError { line: 175, col: 1, msg: "expecting \"[Some('\\'')]\" but found EOF." })

The file is /usr/share/applications/org.kde.ktnef.desktop from the package https://packages.ubuntu.com/noble/ktnef:

[Desktop Entry]
Name=KTnef
Name[af]=KTnef
Name[ar]=KTnef
Name[az]=KTnef
Name[bg]=KTnef
Name[br]=KTnef
Name[bs]=KTnef
Name[ca]=KTnef
Name[ca@valencia]=KTnef
Name[cs]=KTnef
Name[cy]=KTnef
Name[da]=KTnef
Name[de]=KTnef
Name[el]=KTnef
Name[en_GB]=KTnef
Name[eo]=KTnef
Name[es]=KTnef
Name[et]=KTnef
Name[eu]=KTnef
Name[fi]=KTnef
Name[fr]=KTnef
Name[fy]=KTnef
Name[ga]=KTnef
Name[gl]=KTnef
Name[he]=KTnef
Name[hu]=KTnef
Name[ia]=KTnef
Name[it]=KTnef
Name[ja]=KTnef
Name[ka]=KTnef
Name[kk]=KTnef
Name[km]=KTnef
Name[ko]=KTnef
Name[lt]=KTnef
Name[mr]=KTnef
Name[ms]=KTnef
Name[nb]=KTnef
Name[nds]=KTnef
Name[ne]=KTnef
Name[nl]=KTnef
Name[pl]=KTnef
Name[pt]=KTnef
Name[pt_BR]=KTnef
Name[ro]=KTnef
Name[ru]=KTnef
Name[sk]=KTnef
Name[sl]=KTnef
Name[sr]=К‑тнеф
Name[sr@ijekavian]=К‑тнеф
Name[sr@ijekavianlatin]=KTnef
Name[sr@latin]=KTnef
Name[sv]=Ktnef
Name[ta]=KTnef
Name[tr]=KTnef
Name[ug]=KTnef
Name[uk]=KTnef
Name[wa]=KTnef
Name[x-test]=xxKTnefxx
Name[zh_CN]=KTnef
Name[zh_TW]=KTnef
GenericName=TNEF File Viewer (proprietary format used by outlook)
GenericName[ar]=عارض ملفّات TNEF (نسق مملوك يستخدمه «آوتلوك»)
GenericName[az]=TNEF faylı bələdçisi (outlook tərəfindən istifadə olunan xüsiusi format)
GenericName[bg]=Преглед на TNEF файлове (патентован формат, използван от outlook)
GenericName[bs]=TNEF File Viewer (zakonom zaštićeni format korišten od strane outlook-a)
GenericName[ca]=Visualitzador de fitxers TNEF (format usat per l'Outlook)
GenericName[ca@valencia]=Visor de fitxers TNEF (format utilitzat per Outlook)
GenericName[da]=TNEF-filfremviser (proprietært format som bruges af outlook)
GenericName[de]=TNEF-Dateibetrachter (Proprietäres Format von Outlook)
GenericName[el]=Προβολέας αρχείων TNEF (ιδιοταγής μορφή που χρησιμοποιείται από το outlook)
GenericName[en_GB]=TNEF File Viewer (proprietary format used by outlook)
GenericName[eo]=TNEF File Viewer (proprieta formato uzata de Outlook)
GenericName[es]=Visor de archivos TNEF (formato propietario usado por outlook)
GenericName[et]=TNEF-failide (Outlookis kasutatav omanduslik vorming) näitaja
GenericName[eu]=TNEF fitxategi erakuslea (outlook-ek erabiltzen duen formatu jabeduna)
GenericName[fi]=TNEF-tiedostokatselin (Outlookin käyttämä suljettu tiedostomuoto)
GenericName[fr]=Afficheur de fichier « TNEF » (Format propriétaire utilisé par « Outlook »)
GenericName[gl]=Visor de ficheiros de TNEF (formato privativo usado por outlook)
GenericName[hu]=TNEF fájlmegjelenítő (az outlook által használt zárt formátum)
GenericName[ia]=Visor de file TNEF (formato proprietari usate per outlook)
GenericName[it]=Visualizzatore di file TNEF (formato proprietario usato da Outlook)
GenericName[ka]=TNEF ფაილების დათვალიერება (outlook-ის მიერ გამოყენებული დახურული ფორმატი)
GenericName[kk]=TNEF файлын қарау құралы (Outlook-та қолданатын меншікті пішім)
GenericName[ko]=TNEF 파일 뷰어(Outlook에서 사용하는 형식)
GenericName[nb]=TNEF filviser (godseid format som outlook bruker)
GenericName[nds]=TNEF-Dateikieker (warflich Egenformaat vun Outlook)
GenericName[nl]=TNEF Bestandsviewer (formaat met eigendomsrechten gebruikt door outlook)
GenericName[nn]=TNEF-lesar (lukka format brukt av Outlook)
GenericName[pl]=Przeglądarka plików TNEF (Outlook)
GenericName[pt]=Visualizador de Ficheiros TNEF (formato proprietário usado pelo Outlook)
GenericName[pt_BR]=Visualizador de TNEF (formato usado pelo Outlook)
GenericName[ru]=Просмотр файлов TNEF (закрытого формата, свойственного outlook)
GenericName[sk]=Prehliadač súborov TNEF (proprietárny formát používaný Outlookom)
GenericName[sl]=Pregledovalnik datotek TNEF (lastniška vrsta, ki jo uporablja Outlook)
GenericName[sr]=Приказивач ТНЕФ фајлова (власнички формат из Аутлука)
GenericName[sr@ijekavian]=Приказивач ТНЕФ фајлова (власнички формат из Аутлука)
GenericName[sr@ijekavianlatin]=Prikazivač TNEF fajlova (vlasnički format iz Outlooka)
GenericName[sr@latin]=Prikazivač TNEF fajlova (vlasnički format iz Outlooka)
GenericName[sv]=TNEF-filvisare (tillverkarspecifikt format använt av Outlook)
GenericName[ta]=TNEF கோப்புகளை காட்டுவது (அவுட்லுக் பயன்படுத்தும் கோப்பு வடிவம்)
GenericName[tr]=TNEF Dosya Görüntüleyici (Outlook tarafından kullanılan sahipli biçim)
GenericName[uk]=Засіб перегляду файлів TNEF (закритого формату даних, що використовується Outlook)
GenericName[x-test]=xxTNEF File Viewer (proprietary format used by outlook)xx
GenericName[zh_CN]=TNEF 文件查看器 (Outlook 使用的专有格式)
GenericName[zh_TW]=TNEF 檔案檢視器(outlook 所使用的私有格式)
Exec=ktnef %f
Icon=ktnef
Type=Application
X-DocPath=ktnef/index.html
Comment=A viewer/extractor for TNEF files
Comment[af]='n Leeser en data onttrekker vir TNEF lêers
Comment[ar]=عارض/مستخرج لملفّات TNEF
Comment[az]=TNEF faylları üçün bələdçi/çıxarıcı
Comment[bg]=Програма за преглед и извличане на файлове TNEF
Comment[bs]=Pregledač/izdvajač iz TNEF datoteka
Comment[ca]=Un visualitzador/extractor per als fitxers TNEF
Comment[ca@valencia]=Un visor/extractor per als fitxers TNEF
Comment[cy]=Gwelydd/echdynnydd i ffeiliau TNEF
Comment[da]=En fremviser/udpakker til TNEF-filer
Comment[de]=Betrachten und Extrahieren von TNEF-Dateien
Comment[el]=Ένας προβολέας/εξαγωγέας για αρχεία TNEF
Comment[en_GB]=A viewer/extractor for TNEF files
Comment[eo]=Vidilo/ekstraktilo por TNEF-dosieroj
Comment[es]=Un visor/extractor para archivos TNEF
Comment[et]=TNEF-failide näitaja/ekstraktija
Comment[eu]=TNEF fitxategien erakusle/erauzle bat
Comment[fa]=یک مشاهده‌گر/استخراج‌گر برای پرونده‌های TNEF
Comment[fi]=Näytin/purkaja TNEF-tiedostoille
Comment[fr]=Un afficheur / extracteur de fichier TNEF
Comment[fy]=In werjefteprogramma/útpakker foar TNEF-triemmen
Comment[gl]=Un visor/extractor de ficheiros TNEF
Comment[hr]=Prikazivač/izdvajač za TNEF datoteke
Comment[hu]=Egy megjelenítő/kibontó a TNEF fájlokhoz
Comment[ia]=Un visor/extractor de files TNEF
Comment[it]=Un visualizzatore/estrattore di file TNEF
Comment[ja]=TNEF ファイルのためのビューア/展開ツール
Comment[ka]=TNEF ფალების ნახვა/გაშლა
Comment[kk]=TNEF файдарды қарау/тарқату
Comment[km]=កម្មវិធី​មើល/កម្មវិធី​ស្រង់​ចេញ​សម្រាប់​ឯកសារ TNEF
Comment[ko]=TNEF 파일 표시/내용 추출
Comment[lt]=TNEF failų žiūryklė, išskleidimo programa
Comment[mr]=TNEF फाईल्स करिता प्रदर्शक/बाहेर काढणारा
Comment[ms]=Pemapar/pengekstrak untuk fail TNEF 
Comment[nb]=En viser/filuttrekker for TNEF-filer
Comment[nds]=TNEF-Dateien ankieken un Delen ruttrecken
Comment[ne]=TNEF फाइलका लागि दर्शक/निष्कासक
Comment[nl]=Een viewer/extractor voor TNEF-bestanden
Comment[nn]=Program for handsaming av TNEF-filer (vising og utpakking)
Comment[pl]=Przeglądarka/program rozpakowujący dla plików TNEF
Comment[pt]=Um visualizador/extractor de ficheiros TNEF
Comment[pt_BR]=Um visualizador/extrator de arquivos TNEF
Comment[ro]=Un vizualizator/extractor pentru fișiere TNEF
Comment[ru]=Просмотр и распаковка файлов TNEF
Comment[sk]=Prehliadač/extrahovač pre TNEF subory
Comment[sl]=Pregledovalnik/program za izvleko datotek TNEF
Comment[sr]=Приказивач/издвајач за ТНЕФ фајлове
Comment[sr@ijekavian]=Приказивач/издвајач за ТНЕФ фајлове
Comment[sr@ijekavianlatin]=Prikazivač/izdvajač za TNEF fajlove
Comment[sr@latin]=Prikazivač/izdvajač za TNEF fajlove
Comment[sv]=Visnings- och extraktionsprogram för TNEF-filer
Comment[ta]=TNEF கோப்புகளை காட்டுவது/பிரித்தெடுப்பது
Comment[tg]=Намоиш ва боз кардани файлҳои TNEF
Comment[tr]=TNEF dosyaları için bir görüntüleyici/çıkarıcı
Comment[ug]=TNEF ھۆججەتلىرىتى ئۈچۈن كۆرگۈ ۋە ئىجرا قىلغۇ
Comment[uk]=Програма для перегляду і видобування файлів у форматі TNEF
Comment[wa]=On håyneu/saetcheu foû po les fitchîs TNEF
Comment[x-test]=xxA viewer/extractor for TNEF filesxx
Comment[zh_CN]=TNEF 文件的查看/提取器
Comment[zh_TW]=TNEF 檔案檢視器
MimeType=application/ms-tnef;
Categories=Qt;KDE;X-KDE-Utilities-PIM;Office;Network;Email;
X-DBUS-ServiceName=org.kde.ktnef

The file contains 174 lines, with the last one being an empty line. The parsing error occurs on line 175. I don't know if that helps.

AllanDaemon commented 2 months ago

Full backtrace:

thread 'main' panicked at src/providers.rs:45:41:
called `Result::unwrap()` on an `Err` value: Parse(ParseError { line: 175, col: 1, msg: "expecting \"[Some('\\'')]\" but found EOF." })
stack backtrace:
   0:     0x5a38d2079c15 - std::backtrace_rs::backtrace::libunwind::trace::h23054e327d0d4b55
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/../../backtrace/src/backtrace/libunwind.rs:116:5
   1:     0x5a38d2079c15 - std::backtrace_rs::backtrace::trace_unsynchronized::h0cc587407d7f7f64
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x5a38d2079c15 - std::sys_common::backtrace::_print_fmt::h4feeb59774730d6b
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:68:5
   3:     0x5a38d2079c15 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::hd736fd5964392270
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:44:22
   4:     0x5a38d2097e4b - core::fmt::rt::Argument::fmt::h105051d8ea1ade1e
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/fmt/rt.rs:165:63
   5:     0x5a38d2097e4b - core::fmt::write::hc6043626647b98ea
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/fmt/mod.rs:1168:21
   6:     0x5a38d20778bf - std::io::Write::write_fmt::h0d24b3e0473045db
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/io/mod.rs:1835:15
   7:     0x5a38d20799ee - std::sys_common::backtrace::_print::h62df6fc36dcebfc8
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:47:5
   8:     0x5a38d20799ee - std::sys_common::backtrace::print::h45eb8174d25a1e76
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:34:9
   9:     0x5a38d207ad89 - std::panicking::default_hook::{{closure}}::haf3f0170eb4f3b53
  10:     0x5a38d207ab2a - std::panicking::default_hook::hb5d3b27aa9f6dcda
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:298:9
  11:     0x5a38d207b223 - std::panicking::rust_panic_with_hook::h6b49d59f86ee588c
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:795:13
  12:     0x5a38d207b104 - std::panicking::begin_panic_handler::{{closure}}::hd4c2f7ed79b82b70
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:664:13
  13:     0x5a38d207a0d9 - std::sys_common::backtrace::__rust_end_short_backtrace::h2946d6d32d7ea1ad
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:171:18
  14:     0x5a38d207ae37 - rust_begin_unwind
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:652:5
  15:     0x5a38d1f181f3 - core::panicking::panic_fmt::ha02418e5cd774672
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/panicking.rs:72:14
  16:     0x5a38d1f186e6 - core::result::unwrap_failed::h55f86ada3ace5ed2
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/result.rs:1679:5
  17:     0x5a38d1f1c657 - core::result::Result<T,E>::unwrap::hf3c7dafb80467330
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/result.rs:1102:23
  18:     0x5a38d1f1c657 - uchoose::providers::get_app_desktop_ini::h9b976312d0e94d77
                               at /data/code/uchoose/uchoose-rs/src/providers.rs:45:15
  19:     0x5a38d1f1cb3e - uchoose::providers::get_browser_desktop_list::h4ff40150e591bba2
                               at /data/code/uchoose/uchoose-rs/src/providers.rs:62:9
  20:     0x5a38d1f1cbc6 - uchoose::providers::main_dev::h1a1aec87c9607265
                               at /data/code/uchoose/uchoose-rs/src/providers.rs:69:5
  21:     0x5a38d1f25e87 - uchoose::main::hd763ea5db1c9e8f3
                               at /data/code/uchoose/uchoose-rs/src/main.rs:57:5
  22:     0x5a38d1f2a3cb - core::ops::function::FnOnce::call_once::h71c6f6fe816cdc9f
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/ops/function.rs:250:5
  23:     0x5a38d1f2355e - std::sys_common::backtrace::__rust_begin_short_backtrace::h448cac471570a7fc
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/sys_common/backtrace.rs:155:18
  24:     0x5a38d1f1bfc1 - std::rt::lang_start::{{closure}}::hefa4fe1f1c5cc290
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/rt.rs:159:18
  25:     0x5a38d20739ed - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::hf57beef1b8c334ce
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/core/src/ops/function.rs:284:13
  26:     0x5a38d20739ed - std::panicking::try::do_call::h65791b6ab5d9b39f
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:559:40
  27:     0x5a38d20739ed - std::panicking::try::h5a3dd25e8a379a23
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:523:19
  28:     0x5a38d20739ed - std::panic::catch_unwind::he2ce8403bab77de2
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panic.rs:149:14
  29:     0x5a38d20739ed - std::rt::lang_start_internal::{{closure}}::h0b55d0da19178545
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/rt.rs:141:48
  30:     0x5a38d20739ed - std::panicking::try::do_call::h33cbeb674c7644e0
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:559:40
  31:     0x5a38d20739ed - std::panicking::try::h530c58b4c9daadba
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panicking.rs:523:19
  32:     0x5a38d20739ed - std::panic::catch_unwind::h92e02677901e11e4
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/panic.rs:149:14
  33:     0x5a38d20739ed - std::rt::lang_start_internal::hcee5ed89fc25829a
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/rt.rs:141:20
  34:     0x5a38d1f1bf9a - std::rt::lang_start::h89029f16c6892707
                               at /rustc/3f5fd8dd41153bc5fdca9427e9e05be2c767ba23/library/std/src/rt.rs:158:17
  35:     0x5a38d1f278be - main
  36:     0x7cbcfa62a1ca - __libc_start_call_main
                               at ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
  37:     0x7cbcfa62a28b - __libc_start_main_impl
                               at ./csu/../csu/libc-start.c:360:3
  38:     0x5a38d1f18b65 - _start
  39:                0x0 - <unknown>
zonyitoo commented 2 months ago
Comment[af]='n Leeser en data onttrekker vir TNEF lêers

I guess the ' in this line was the cause. ' is the start mark of a quoted string.

https://github.com/zonyitoo/rust-ini/blob/fd0725a45d7cd1c3f4b7b0800d69cd7214230c18/src/lib.rs#L194-L206

You may try to set enable_quote to false.

AllanDaemon commented 2 months ago

As I don't use the package with this file, I just uninstalled it, and it solved for now for me.

But if I have this issue again, I'll try the recommended.

I opened the issue in the hope of helping the package. Feel free to close it if want it.