Skip to content

Commit

Permalink
fix(ics): removes maxlen for all fields (#58) (#83)
Browse files Browse the repository at this point in the history
Removes the max length truncation for SUMMARY, LOCATION, and
DESCRIPTION, in accordance with RFC-5545.
  • Loading branch information
jshor authored Apr 29, 2020
1 parent 64ce610 commit 7cf979e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/ICalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ export default class ICalendar extends CalendarBase {
* @returns {String}
*/
render () {
const description = formatText(this.description, 62)
const location = formatText(this.location, 64)
const summary = formatText(this.title, 66)
const description = formatText(this.description)
const location = formatText(this.location)
const summary = formatText(this.title)
const event = [
'CLASS:PUBLIC',
`DESCRIPTION:${description}`,
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/ICalendar.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ describe('ICalendar', () => {
'VERSION:2.0',
'BEGIN:VEVENT',
'CLASS:PUBLIC',
`DESCRIPTION:${baseOpts.description} formatted 62`,
`DESCRIPTION:${baseOpts.description}`,
`DTSTART:${moment(baseOpts.start).format(dtFormat)}`,
`DTEND:${moment(baseOpts.end).format(dtFormat)}`,
`LOCATION:${baseOpts.location} formatted 64`,
`SUMMARY:${baseOpts.title} formatted 66`,
`LOCATION:${baseOpts.location}`,
`SUMMARY:${baseOpts.title}`,
'TRANSP:TRANSPARENT',
'END:VEVENT',
'END:VCALENDAR',
Expand Down
6 changes: 0 additions & 6 deletions src/utils/__tests__/ics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,6 @@ describe('IcsUtil', () => {

expect(formatted).toBe('foo\\nbar\\n\\nbaz')
})

it('should truncate the string after backslash escaping newlines', () => {
const formatted = formatText(str, 10)

expect(formatted).toBe('foo\\nbar\\n')
})
})

describe('getBlob()', () => {
Expand Down
9 changes: 3 additions & 6 deletions src/utils/ics.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,14 @@ import safariFileSave from './safariFileSave'
* longer than maxLength chars (or 75 chars if none specified).
*
* @param {String} str - string to sanitize
* @param {Number} maxLength
* @returns {String}
*/
export const formatText = (str, maxLength) => {
export const formatText = (str) => {
if (!str) {
return ''
}
str = str.replace(/\n/g, '\\n')
str = str.substring(0, maxLength)

return str

return str.replace(/\n/g, '\\n')
}

/**
Expand Down

0 comments on commit 7cf979e

Please sign in to comment.