Closed Bug 1587551 Opened 4 months ago Closed 4 months ago

Export CSV is corrupt when Notes field on Other tab has quotation marks in it


(Thunderbird :: Address Book, defect)

Not set


(thunderbird_esr6870+ fixed, thunderbird70 fixed, thunderbird71 fixed)

Thunderbird 71.0
Tracking Status
thunderbird_esr68 70+ fixed
thunderbird70 --- fixed
thunderbird71 --- fixed


(Reporter: jik, Assigned: jik)



(1 file)

  1. Create an entry in your address book with this in the Notes field on the Other tab: "Other" number is foobar..

  2. Export the address book.

  3. Note how the CSV field contains this in the Notes column for the entry: """Other" ""umber is foobar."

  4. What it should contain is: """Other"" number is foobar."

This makes the exported CSV impossible to import successfully into Thunderbird; the import will be corrupt.

This bug goes back to at least Thunderbird 60; I did not test earlier versions than that.

Ever confirmed: false

I believe the bug is this code in nsAbManager::ExportDirectoryToDelimitedText in nsAbManager.cpp:

                while (offset < newValue.Length()) {
                  match = newValue.Find(oldSubstr, offset);
                  if (match == -1) break;

                  newValue.Replace(offset + match, oldSubstr.Length(),
                  offset += (match + newSubstr.Length());

The problem, I think, is that nsAutoString::Find returns an absolute offset from the beginning of the string, not an offset from the beginning of the search, so the first argument to Replace should be match, not offset + match.

Confirmed, this fixes it.

Assignee: nobody → jik
Attachment #9099994 - Flags: review?(jorgk)
Comment on attachment 9099994 [details] [diff] [review]
Fix Address Book CSV export of strings with quotation marks

> Find returns an absolute offset from the beginning of the string, not an offset from the beginning of the search.

Correct. Thanks for the fix. I also tested it. I'll land it now. I'll take care of the formatting issue. clang-format wants to fill the preceding line.
Attachment #9099994 - Flags: review?(jorgk)
Attachment #9099994 - Flags: review+
Attachment #9099994 - Flags: approval-comm-esr68+
Attachment #9099994 - Flags: approval-comm-beta+

Pushed by
Fix address book CSV export when Notes field contains quotation marks. r=jorgk

Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → Thunderbird 71.0
You need to log in before you can comment on or make changes to this bug.