Forum Replies Created

Viewing 1 replies (of 1 total)
  • Thread Starter phiphoart

    (@phiphoart)

    Bug: “Add to Google Calendar” link breaks for Cyrillic (and all non-Latin) characters

    Plugin version: 3.6.2 PHP version: 8.2.30 WordPress version: 6.9.4

    Problem: When clicking “Add to Google Calendar”, event titles and descriptions containing Cyrillic characters (Bulgarian, Russian, etc.) are completely stripped or garbled. The title shows only Latin characters or nothing, and the description shows raw HTML markup like b2030 0100 b 12 brbbr hrefhttps...

    This affects any non-Latin language: Cyrillic, Greek, Chinese, Arabic, etc.

    Root cause — two bugs in two files:

    1. includes/abstracts/calendar.phpget_add_to_gcal_url() method

    The params array uses urlencode() and then the whole thing goes through sanitize_text_field() which strips non-ASCII characters, and then esc_url() which strips them again. Three layers of destruction.

    Fix — replace:

    php

    $params = [
        'action' => 'TEMPLATE',
        'text' => urlencode(strip_tags($event->title)),
        'dates' => $gcal_dt_string,
        'details' => urlencode($event->description),
        'location' => urlencode($event->start_location['address']),
        'trp' => 'false',
    ];
    $params = array_map('sanitize_text_field', $params);
    $url = esc_url(add_query_arg($params, sanitize_url($base_url)));

    With:

    php

    $params = [
        'action' => 'TEMPLATE',
        'text' => rawurlencode(strip_tags($event->title)),
        'dates' => $gcal_dt_string,
        'details' => rawurlencode(strip_tags($event->description)),
        'location' => rawurlencode(strip_tags($event->start_location['address'])),
        'trp' => 'false',
    ];
    $url = $base_url . '?' . implode('&', array_map(
        function($k, $v) { return $k . '=' . $v; },
        array_keys($params),
        array_values($params)
    ));

    2. includes/events/event-builder.phpmake_link() method

    esc_url() strips percent-encoded non-ASCII characters from the already-correctly-encoded URL.

    Fix — replace:

    php

    ? ' <a href="' .
            esc_url($url) .

    With:

    php

    ? ' <a href="' .
            ('add-to-gcal-link' === $tag ? esc_attr($url) : esc_url($url)) .

    Both fixes together produce a correctly encoded Google Calendar URL that passes Cyrillic, Greek, Chinese and all other Unicode characters through intact.

    Good luck, and благодаря for the fun debugging session! 🙌

Viewing 1 replies (of 1 total)