Skip to content

Commit

Permalink
[CP-2968] add clean of escape characters for vcard (#2024)
Browse files Browse the repository at this point in the history
  • Loading branch information
lkowalczyk87 committed Aug 14, 2024
1 parent e872a36 commit f9ca04a
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,25 @@ export const mapVcard = (data: jCard[]): UnifiedContact[] => {
return results
}

const cleanEscapeCharacters = (value: string) => {
return value
.replace(/\\"/g, '"')
.replace(/\\n/g, "\n")
.replace(/\\r/g, "\r")
.replace(/\\,/g, ",")
.replace(/\\;/g, ";")
.replace(/\\:/g, ":")
.replace(/\\/g, "\\")
}

const getFields = (item: jCard, key: string) => {
const fields = item[1].filter((property) => property[0] === key)
return fields
.map((field) => {
const type = isArray(field[1].type) ? last(field[1].type) : field[1].type
const value = field[3]
const value = isArray(field[3])
? field[3].map(cleanEscapeCharacters)
: cleanEscapeCharacters(field[3])
return { type, value }
})
.filter(({ value }) => value)
Expand Down

0 comments on commit f9ca04a

Please sign in to comment.