<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.kde.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugs.kde.org/"
          
          maintainer="sysadmin@kde.org"
>

    <bug>
          <bug_id>463246</bug_id>
          
          <creation_ts>2022-12-19 18:51:17 +0000</creation_ts>
          <short_desc>Importing CSV&apos;s with double-sets of quotes (&quot;&quot;) splits the field</short_desc>
          <delta_ts>2024-12-19 10:13:09 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>2</classification_id>
          <classification>Applications</classification>
          <product>kmymoney</product>
          <component>importer</component>
          <version>5.1.3</version>
          <rep_platform>Other</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>NOR</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>matt</reporter>
          <assigned_to name="KMyMoney Devel Mailing List">kmymoney-devel</assigned_to>
          <cc>alx.kuzza</cc>
    
    <cc>matt</cc>
          
          <cf_commitlink>https://invent.kde.org/office/kmymoney/commit/fc8f557ef56d07faf369ecc5ab917f5ef119493d</cf_commitlink>
          <cf_versionfixedin>5.2</cf_versionfixedin>
          <cf_sentryurl></cf_sentryurl>
          <votes>0</votes>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2187085</commentid>
    <comment_count>0</comment_count>
    <who name="">matt</who>
    <bug_when>2022-12-19 18:51:17 +0000</bug_when>
    <thetext>SUMMARY
I&apos;m attempting to import Amazon Item Exports for reconciliation.
Amazon&apos;s Description column uses `&quot;&quot;` to indicate a &quot; symbol (since &quot; is used for surrounding a field).  While LibreOffice handles this fine, KMyMoney treats that as a field delimiter, even though I&apos;ve specified that fields are delimited by a comma (,).
This forces me to have to perform manual manipulation before importing, and is against spec.

Thank you!

STEPS TO REPRODUCE
1. Create a CSV file with a line where the description field has a &quot;&quot;
    (eg.    &quot;The thing we purchased measures 4&quot;&quot;x6&quot;&quot;.&quot; )
2. Import that CSV into KMyMoney
3. Look at the fields, and you&apos;ll see the &quot;x6&quot; and &quot;.&quot; have their own fields.

OBSERVED RESULT
A few of my hundreds of lines parsed incorrectly, with &quot;additional fields&quot; that don&apos;t exist in other transactions, because the &quot; symbol is necessary for data and the imported CSV uses &quot;&quot; to cause a &quot; symbol to be part of the data.

EXPECTED RESULT
I expect the CSV to be parsed correctly, where fields are only separated by a comma, if the comma is not within &quot;-symbols, and &quot;&quot; causes a &quot; symbol to be part of the data.

SOFTWARE/OS VERSIONS
Windows: 
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 

ADDITIONAL INFORMATION</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2187088</commentid>
    <comment_count>1</comment_count>
    <who name="">alx.kuzza</who>
    <bug_when>2022-12-19 19:44:50 +0000</bug_when>
    <thetext>Could you, please, attach a fragment of the CSV file you are talking about?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2187095</commentid>
    <comment_count>2</comment_count>
    <who name="">matt</who>
    <bug_when>2022-12-19 21:10:25 +0000</bug_when>
    <thetext>https://www.rfc-editor.org/rfc/rfc4180

```
2.  Definition of the CSV Format
   ...
   7.  If double-quotes are used to enclose fields, then a double-quote
       appearing inside a field must be escaped by preceding it with
       another double quote.  For example:

       &quot;aaa&quot;,&quot;b&quot;&quot;bb&quot;,&quot;ccc&quot;
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2187103</commentid>
    <comment_count>3</comment_count>
    <who name="Jack">ostroffjh</who>
    <bug_when>2022-12-19 21:36:02 +0000</bug_when>
    <thetext>It really would make it easier if you provide a sample csv file, even if it&apos;s only a header and one data row.  It may be obvious to you what is wrong, but debugging to find exactly where in the code the problem occurs is easier if the developers have a real example to trace through.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2187306</commentid>
    <comment_count>4</comment_count>
    <who name="">matt</who>
    <bug_when>2022-12-20 15:20:13 +0000</bug_when>
    <thetext>(In reply to alx.kuzza from comment #1)
&gt; Could you, please, attach a fragment of the CSV file you are talking about?

Sure!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2187307</commentid>
    <comment_count>5</comment_count>
      <attachid>154711</attachid>
    <who name="">matt</who>
    <bug_when>2022-12-20 15:25:23 +0000</bug_when>
    <thetext>Created attachment 154711
Test CSV

This is a test CSV.  It includes a header (so the fields are understandable) directly from Amazon&apos;s Item Download.
Two entries are included, left mostly unmodified.  The first entry should parse fine.  The second line will break up the string in field 3 and stick &quot;650-Sheet Capacity&quot; into field 4.

Please accept my apologies, it appears my original description is likely off.  It seems that, while the fields are not breaking at the double-quote (&quot;&quot;), KMyMoney appears to &quot;stop protecting commas&quot; such that commas after a &quot;&quot; are treated as delimiters, not string text.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2187308</commentid>
    <comment_count>6</comment_count>
    <who name="">matt</who>
    <bug_when>2022-12-20 15:26:11 +0000</bug_when>
    <thetext>(In reply to Jack from comment #3)
&gt; It really would make it easier if you provide a sample csv file, even if
&gt; it&apos;s only a header and one data row.  It may be obvious to you what is
&gt; wrong, but debugging to find exactly where in the code the problem occurs is
&gt; easier if the developers have a real example to trace through.

That&apos;s totally reasonable.
And a good request, since I realized that my original description was likely misleading.  Please see test file and accompanying note.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2187310</commentid>
    <comment_count>7</comment_count>
    <who name="">matt</who>
    <bug_when>2022-12-20 15:27:35 +0000</bug_when>
    <thetext>Thank you for fast responses, and more thanks for creating such a powerful, beautiful, and friendly piece of F/OSS money-management software!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2187734</commentid>
    <comment_count>8</comment_count>
    <who name="">alx.kuzza</who>
    <bug_when>2022-12-21 08:53:04 +0000</bug_when>
    <thetext>(In reply to matt from comment #0)
&gt; SUMMARY
&gt; I&apos;m attempting to import Amazon Item Exports for reconciliation.
&gt; Amazon&apos;s Description column uses `&quot;&quot;` to indicate a &quot; symbol (since &quot; is
&gt; used for surrounding a field).  While LibreOffice handles this fine,
&gt; KMyMoney treats that as a field delimiter, even though I&apos;ve specified that
&gt; fields are delimited by a comma (,).
&gt; This forces me to have to perform manual manipulation before importing, and
&gt; is against spec.
&gt; 
&gt; Thank you!
&gt; 
&gt; STEPS TO REPRODUCE
&gt; 1. Create a CSV file with a line where the description field has a &quot;&quot;
&gt;     (eg.    &quot;The thing we purchased measures 4&quot;&quot;x6&quot;&quot;.&quot; )
&gt; 2. Import that CSV into KMyMoney
&gt; 3. Look at the fields, and you&apos;ll see the &quot;x6&quot; and &quot;.&quot; have their own fields.
&gt; 
&gt; OBSERVED RESULT
&gt; A few of my hundreds of lines parsed incorrectly, with &quot;additional fields&quot;
&gt; that don&apos;t exist in other transactions, because the &quot; symbol is necessary
&gt; for data and the imported CSV uses &quot;&quot; to cause a &quot; symbol to be part of the
&gt; data.
&gt; 
&gt; EXPECTED RESULT
&gt; I expect the CSV to be parsed correctly, where fields are only separated by
&gt; a comma, if the comma is not within &quot;-symbols, and &quot;&quot; causes a &quot; symbol to
&gt; be part of the data.
&gt; 
&gt; SOFTWARE/OS VERSIONS
&gt; Windows: 
&gt; macOS: 
&gt; Linux/KDE Plasma: 
&gt; (available in About System)
&gt; KDE Plasma Version: 
&gt; KDE Frameworks Version: 
&gt; Qt Version: 
&gt; 
&gt; ADDITIONAL INFORMATION

Good news, it is reproducible :)
Could you, please, also provide the OS/Version you have a problem with.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2187772</commentid>
    <comment_count>9</comment_count>
    <who name="Bug Janitor Service">bug-janitor</who>
    <bug_when>2022-12-21 13:03:36 +0000</bug_when>
    <thetext>A possibly relevant merge request was started @ https://invent.kde.org/office/kmymoney/-/merge_requests/180</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2187775</commentid>
    <comment_count>10</comment_count>
    <who name="">matt</who>
    <bug_when>2022-12-21 13:31:36 +0000</bug_when>
    <thetext>This is reproducible on Kubuntu 22.04 running the KMyMoney-5.1-322-linux-gcc--x86_64.AppImage AppImage (Version 5.1.3-71876c371)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2189887</commentid>
    <comment_count>11</comment_count>
    <who name="Thomas Baumgart">tbaumgart</who>
    <bug_when>2022-12-28 15:46:53 +0000</bug_when>
    <thetext>Git commit 33879f13b955753214385bc1c67e77c6d510a7d5 by Thomas Baumgart, on behalf of Alexander Kuznetsov.
Committed on 28/12/2022 at 15:46.
Pushed by tbaumgart into branch &apos;master&apos;.

Fix CSV parser to correctly support quoted cells

M  +60   -33   kmymoney/plugins/csv/import/core/csvutil.cpp
M  +23   -11   kmymoney/plugins/csv/import/core/tests/parsedata-test.cpp

https://invent.kde.org/office/kmymoney/commit/33879f13b955753214385bc1c67e77c6d510a7d5</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2189888</commentid>
    <comment_count>12</comment_count>
    <who name="Thomas Baumgart">tbaumgart</who>
    <bug_when>2022-12-28 15:50:26 +0000</bug_when>
    <thetext>Git commit fc8f557ef56d07faf369ecc5ab917f5ef119493d by Thomas Baumgart, on behalf of Alexander Kuznetsov.
Committed on 28/12/2022 at 15:50.
Pushed by tbaumgart into branch &apos;5.1&apos;.

Fix CSV parser to correctly support quoted cells 

Backported from master
FIXED-IN: 5.1.4

M  +2    -0    .gitignore
M  +40   -13   kmymoney/plugins/csv/import/core/csvutil.cpp
M  +21   -11   kmymoney/plugins/csv/import/core/tests/parsedata-test.cpp

https://invent.kde.org/office/kmymoney/commit/fc8f557ef56d07faf369ecc5ab917f5ef119493d</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2195143</commentid>
    <comment_count>13</comment_count>
    <who name="">matt</who>
    <bug_when>2023-01-09 22:16:15 +0000</bug_when>
    <thetext>Downloaded AppImage KMyMoney-5.1-348-linux-gcc-x86_64.AppImage and parsing appears to work correctly.  Thank you!</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>154711</attachid>
            <date>2022-12-20 15:25:23 +0000</date>
            <delta_ts>2022-12-20 15:25:23 +0000</delta_ts>
            <desc>Test CSV</desc>
            <filename>test.csv</filename>
            <type>text/csv</type>
            <size>1416</size>
            <attacher>matt</attacher>
            
              <data encoding="base64">T3JkZXIgRGF0ZSxPcmRlciBJRCxUaXRsZSxDYXRlZ29yeSxBU0lOL0lTQk4sVU5TUFNDIENvZGUs
V2Vic2l0ZSxSZWxlYXNlIERhdGUsQ29uZGl0aW9uLFNlbGxlcixTZWxsZXIgQ3JlZGVudGlhbHMs
TGlzdCBQcmljZSBQZXIgVW5pdCxQdXJjaGFzZSBQcmljZSBQZXIgVW5pdCxRdWFudGl0eSxQYXlt
ZW50IEluc3RydW1lbnQgVHlwZSxQdXJjaGFzZSBPcmRlciBOdW1iZXIsUE8gTGluZSBOdW1iZXIs
T3JkZXJpbmcgQ3VzdG9tZXIgRW1haWwsU2hpcG1lbnQgRGF0ZSxTaGlwcGluZyBBZGRyZXNzIE5h
bWUsU2hpcHBpbmcgQWRkcmVzcyBTdHJlZXQgMSxTaGlwcGluZyBBZGRyZXNzIFN0cmVldCAyLFNo
aXBwaW5nIEFkZHJlc3MgQ2l0eSxTaGlwcGluZyBBZGRyZXNzIFN0YXRlLFNoaXBwaW5nIEFkZHJl
c3MgWmlwLE9yZGVyIFN0YXR1cyxDYXJyaWVyIE5hbWUgJiBUcmFja2luZyBOdW1iZXIsSXRlbSBT
dWJ0b3RhbCxJdGVtIFN1YnRvdGFsIFRheCxJdGVtIFRvdGFsLFRheCBFeGVtcHRpb24gQXBwbGll
ZCxUYXggRXhlbXB0aW9uIFR5cGUsRXhlbXB0aW9uIE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