BUG: Newlines are injected into FN: (full name) #7

Closed
opened 2026-07-25 21:06:23 +02:00 by Arxcis · 1 comment
Collaborator

Problem

Sometimes newlines are injected into the value of FN: in the vCard.

This creates error, when trying to open the vCard:

Removing the newlines manually, fixes the problem.

Root cause?

in vcard.js newlines are injected 3 places.

Here:

export function buildVcard(data = []) {
  let r = 'BEGIN:VCARD\n'

  data.forEach((keyPair) => {
    const [key, val] = keyPair
    r += foldLine(`${parseKey(key)}:${parseVal(val, key)}\n`)
  })

  r += 'END:VCARD'
  return r
}

Here:

function escapeVal(input = '') {
  return input.replaceAll(/([,|;|\\])/gi, '\\$1').replaceAll('\n', '\n\n')
}

And here:

function foldLine(input) {
  if (input.length <= 75) {
    return input // no need to fold
  }
  let res = ''
  let counter = 0

  for (const char of input) {
    res += char
    counter++
    if (counter === 75) {
      res += '\n '
      counter = 0
    }
  }

  // handle cases we might fold without having any further
  // data to add. In such cases we must remove the trailing \n + space.
  return res.replaceAll(/\n\s\n$/gi, '\n') + '\n'
}

Where is the bug? I honestly don't know what to do with this. Do you have an idea @nilsnh ?

best regards, @Arxcis

**Problem** Sometimes newlines are injected into the value of FN: in the vCard. <img src="/attachments/dc41538b-4971-4621-aec0-7d656e30469d" width=450 /> This creates error, when trying to open the vCard: <img src="/attachments/2e67245e-1abc-4a7c-9ab9-f97928cf571c" width=450 /> Removing the newlines manually, fixes the problem. **Root cause?** in `vcard.js` newlines are injected 3 places. Here: ```js export function buildVcard(data = []) { let r = 'BEGIN:VCARD\n' data.forEach((keyPair) => { const [key, val] = keyPair r += foldLine(`${parseKey(key)}:${parseVal(val, key)}\n`) }) r += 'END:VCARD' return r } ``` Here: ```js function escapeVal(input = '') { return input.replaceAll(/([,|;|\\])/gi, '\\$1').replaceAll('\n', '\n\n') } ``` And here: ```js function foldLine(input) { if (input.length <= 75) { return input // no need to fold } let res = '' let counter = 0 for (const char of input) { res += char counter++ if (counter === 75) { res += '\n ' counter = 0 } } // handle cases we might fold without having any further // data to add. In such cases we must remove the trailing \n + space. return res.replaceAll(/\n\s\n$/gi, '\n') + '\n' } ``` Where is the bug? I honestly don't know what to do with this. Do you have an idea @nilsnh ? best regards, @Arxcis
Author
Collaborator

Update of investigation

I found that Facebook actually injects \n in the middle of names on screens with smaller width... 🤷‍♂️ Ok.

For now, I will just try to replace them and move on with it. Thanks!

**Update of investigation** I found that Facebook actually injects \n in the middle of names on screens with smaller width... 🤷‍♂️ Ok. For now, I will just try to replace them and move on with it. Thanks!
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
nilsnh/rolodex#7
No description provided.