Skip to content

A platform for community discussion. Free, open, simple.

FIX: Parse RRULE before building Google Calendar URL (#39074)

Régis HANOL6e2f67c2a09e
diff --git a/frontend/discourse/app/lib/download-calendar.js b/frontend/discourse/app/lib/download-calendar.js
index 3856fcac88d..39a0002944e 100644
--- a/frontend/discourse/app/lib/download-calendar.js
+++ b/frontend/discourse/app/lib/download-calendar.js
@@ -52,7 +52,10 @@ export function downloadGoogle(title, dates, options = {}) {
);
if (options.rrule) {
- link.searchParams.append("recur", `RRULE:${options.rrule}`);
+ const rrule = _parseRRule(options.rrule);
+ if (rrule && _hasFreq(rrule)) {
+ link.searchParams.append("recur", `RRULE:${rrule}`);
+ }
}
if (options.location) {
diff --git a/frontend/discourse/tests/unit/lib/download-calendar-test.js b/frontend/discourse/tests/unit/lib/download-calendar-test.js
index 712361b78bc..720a736c3ba 100644
--- a/frontend/discourse/tests/unit/lib/download-calendar-test.js
+++ b/frontend/discourse/tests/unit/lib/download-calendar-test.js
@@ -190,6 +190,30 @@ module("Unit | Utility | download-calendar", function (hooks) {
);
});
+ test("correct url for Google when recurring event with DTSTART prefix", function (assert) {
+ downloadGoogle(
+ "event",
+ [
+ {
+ startsAt: "2021-10-12T15:00:00.000Z",
+ endsAt: "2021-10-12T16:00:00.000Z",
+ },
+ ],
+ {
+ rrule:
+ "DTSTART:20211012T150000Z\nRRULE:FREQ=DAILY;BYDAY=MO,TU,WE,TH,FR",
+ }
+ );
+ assert.true(
+ window.open.calledWith(
+ "https://www.google.com/calendar/event?action=TEMPLATE&text=event&dates=20211012T150000Z%2F20211012T160000Z&recur=RRULE%3AFREQ%3DDAILY%3BBYDAY%3DMO%2CTU%2CWE%2CTH%2CFR",
+ "_blank",
+ "noopener",
+ "noreferrer"
+ )
+ );
+ });
+
test("correct location for Google when location given", function (assert) {
downloadGoogle(
"event",