Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Description line length should not be longer than 75 characters warning in validator #630

Closed
basvdijk opened this issue Dec 24, 2024 · 4 comments

Comments

@basvdijk
Copy link

When I set a large text as description, I get:

Line length should not be longer than 75 characters [near line # 44] Reference: [RFC 5545 3.1. Content Lines](http://icalendar.org/iCalendar-RFC-5545/3-1-content-lines.html)

https://icalendar.org/iCalendar-RFC-5545/3-1-content-lines.html describes that lines should be broken into pieces of 75 chars.

Before using this library I did it manually with this function. Which might be useful:

  function foldICalLine(property, value) {
    const separator = "\n "; // The folding continuation character (newline + space)
    const maxLength = 71 - separator.length; // Maximum line length 75 as per the iCalendar spec
    let foldedLine = `${property}:${value}`; // Combine property and value

    if (foldedLine.length > maxLength) {
      let result = "";
      while (foldedLine.length > maxLength) {
        result += foldedLine.substring(0, maxLength) + separator; // Take first 75 chars and add `\n `
        foldedLine = foldedLine.substring(maxLength); // Remove processed characters
      }
      result += foldedLine; // Add any remaining part
      return result;
    }
    return foldedLine; // Return as-is if no folding is required
  }
@sebbo2002
Copy link
Owner

Which description are you talking about? Can you provide a working example that produces this invalid ical?

Usually this function should fold everything toString() outputs.

@basvdijk
Copy link
Author

basvdijk commented Jan 4, 2025

@sebbo2002 I managed to reproduce the error:

cal.createEvent({
  start: dtStart,
  end: dtEnd,
  location: "Default location",
  summary: "Test summary",
  description:
    "This is a large description with an appointment at Mart's place https://example.com/calendar/item/important-item-219384 which is not truncated correctly",
  status: "CONFIRMED",
});

Gives:

DESCRIPTION:This is a large description with an appointment at Mart's plac
 e https://example.com/calendar/item/important-item-219384 which is not tru
 ncated correctly

The first line is 79 characters long. Probably because of the apostrophe is escaped as 5 characters instead of 1.

@sebbo2002
Copy link
Owner

Okay, that escaping confuses me to be honest. Probably the same issue you have in #629. When I try you example it works completely fine with the current version:

import ical from 'ical-generator'

const cal = ical();
const dtStart = new Date();
const dtEnd = new Date();

cal.createEvent({
  start: dtStart,
  end: dtEnd,
  location: "Default location",
  summary: "Test summary",
  description:
    "This is a large description with an appointment at Mart's place https://example.com/calendar/item/important-item-219384 which is not truncated correctly",
  status: "CONFIRMED",
});

cal.toString();
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//sebbo.net//ical-generator//EN
BEGIN:VEVENT
UID:7e271a95-594a-4c6b-be11-6d0553f0c91c
SEQUENCE:0
DTSTAMP:20250104T162106Z
DTSTART:20250104T162106Z
DTEND:20250104T162106Z
SUMMARY:Test summary
LOCATION:Default location
DESCRIPTION:This is a large description with an appointment at Mart's plac
 e https://example.com/calendar/item/important-item-219384 which is not tru
 ncated correctly
STATUS:CONFIRMED
END:VEVENT
END:VCALENDAR

Bildschirmfoto 2025-01-04 um 17 23 25

Are you using the current ical-generator version v8.0.1 or maybe some old, unfixed version? Is there some code in between that may add that html encoding? Because neither escape() nor foldLines() does any HTML encoding.

@basvdijk
Copy link
Author

basvdijk commented Jan 4, 2025

I am using 11ty and it turned out to escape the output. Thank you so much for your help!

@basvdijk basvdijk closed this as completed Jan 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants