Skip to content

Commit

Permalink
percent encode calendarId used in url
Browse files Browse the repository at this point in the history
Google calendar id may contain some characters
that has special meaning in Url, like '#'.
For example: "cs.czech#holiday@group.v.calendar.google.com".
So, it is necessary to percent encode it, before usage
un url.
  • Loading branch information
Karry committed Mar 16, 2024
1 parent 0d36916 commit d820bdc
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/google/google-calendars/googlecalendarsyncadaptor.cpp
Expand Up @@ -879,6 +879,10 @@ QString toBase32hex(QByteArray bytes)
return result;
}

QString percentEnc(const QString &str) {
return QString::fromUtf8(QUrl::toPercentEncoding(calendarId));
}

QString generate_uuid()
{
// UUID documentation here:
Expand Down Expand Up @@ -1416,7 +1420,7 @@ void GoogleCalendarSyncAdaptor::requestEvents(const QString &accessToken, const
queryItems.append(QPair<QString, QString>(QString::fromLatin1("pageToken"), pageToken));
}

QUrl url(QString::fromLatin1("https://www.googleapis.com/calendar/v3/calendars/%1/events").arg(calendarId));
QUrl url(QString::fromLatin1("https://www.googleapis.com/calendar/v3/calendars/%1/events").arg(percentEnc(calendarId)));
QUrlQuery query(url);
query.setQueryItems(queryItems);
url.setQuery(query);
Expand Down Expand Up @@ -2149,8 +2153,8 @@ void GoogleCalendarSyncAdaptor::upsyncChanges(const UpsyncChange &changeToUpsync
const QByteArray &eventData = changeToUpsync.eventData;

QUrl requestUrl = upsyncType == GoogleCalendarSyncAdaptor::Insert
? QUrl(QString::fromLatin1("https://www.googleapis.com/calendar/v3/calendars/%1/events").arg(calendarId))
: QUrl(QString::fromLatin1("https://www.googleapis.com/calendar/v3/calendars/%1/events/%2").arg(calendarId).arg(eventId));
? QUrl(QString::fromLatin1("https://www.googleapis.com/calendar/v3/calendars/%1/events").arg(percentEnc(calendarId)))
: QUrl(QString::fromLatin1("https://www.googleapis.com/calendar/v3/calendars/%1/events/%2").arg(percentEnc(calendarId)).arg(eventId));

QNetworkRequest request(requestUrl);
request.setRawHeader("GData-Version", "3.0");
Expand Down

0 comments on commit d820bdc

Please sign in to comment.