From d79c8fbf9d3b873147c047610e1886f64b5b3930 Mon Sep 17 00:00:00 2001 From: Carsten Bach Date: Thu, 11 Jul 2024 17:17:35 +0200 Subject: [PATCH 1/5] Add URL encoding to 'Add to calendar' links --- includes/core/classes/class-event.php | 40 +++++++++++++++------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/includes/core/classes/class-event.php b/includes/core/classes/class-event.php index 063479eac..0e827449a 100644 --- a/includes/core/classes/class-event.php +++ b/includes/core/classes/class-event.php @@ -487,15 +487,17 @@ protected function get_google_calendar_link(): string { $location .= sprintf( ', %s', $venue['full_address'] ); } + $params = array( + 'action' => 'TEMPLATE', + 'text' => sanitize_text_field( $this->event->post_title ), + 'dates' => sanitize_text_field( $datetime ), + 'details' => sanitize_text_field( $description ), + 'location' => sanitize_text_field( $location ), + 'sprop' => 'name:', + ); + return add_query_arg( - array( - 'action' => 'TEMPLATE', - 'text' => sanitize_text_field( $this->event->post_title ), - 'dates' => sanitize_text_field( $datetime ), - 'details' => sanitize_text_field( $description ), - 'location' => sanitize_text_field( $location ), - 'sprop' => 'name:', - ), + urlencode_deep( $params ), 'https://www.google.com/calendar/event' ); } @@ -533,17 +535,19 @@ protected function get_yahoo_calendar_link(): string { $location .= sprintf( ', %s', $venue['full_address'] ); } + $params = array( + 'v' => '60', + 'view' => 'd', + 'type' => '20', + 'title' => sanitize_text_field( $this->event->post_title ), + 'st' => sanitize_text_field( $datetime_start ), + 'dur' => sanitize_text_field( (string) $hours . (string) $minutes ), + 'desc' => sanitize_text_field( $description ), + 'in_loc' => sanitize_text_field( $location ), + ); + return add_query_arg( - array( - 'v' => '60', - 'view' => 'd', - 'type' => '20', - 'title' => sanitize_text_field( $this->event->post_title ), - 'st' => sanitize_text_field( $datetime_start ), - 'dur' => sanitize_text_field( (string) $hours . (string) $minutes ), - 'desc' => sanitize_text_field( $description ), - 'in_loc' => sanitize_text_field( $location ), - ), + urlencode_deep( $params ), 'https://calendar.yahoo.com/' ); } From 66e3b03bcfaf49cd5e3462190ba185a03be9c75f Mon Sep 17 00:00:00 2001 From: Carsten Bach Date: Thu, 11 Jul 2024 17:26:24 +0200 Subject: [PATCH 2/5] Remove 1 white-space for CS --- includes/core/classes/class-event.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/core/classes/class-event.php b/includes/core/classes/class-event.php index 0e827449a..c58dd70e5 100644 --- a/includes/core/classes/class-event.php +++ b/includes/core/classes/class-event.php @@ -487,7 +487,7 @@ protected function get_google_calendar_link(): string { $location .= sprintf( ', %s', $venue['full_address'] ); } - $params = array( + $params = array( 'action' => 'TEMPLATE', 'text' => sanitize_text_field( $this->event->post_title ), 'dates' => sanitize_text_field( $datetime ), From dc327cf35df7de56f6acc589bc539090e10c9f88 Mon Sep 17 00:00:00 2001 From: Carsten Bach Date: Thu, 11 Jul 2024 19:00:31 +0200 Subject: [PATCH 3/5] Make unit test aware of url-encoded 'Add to calendar' links --- test/unit/php/includes/core/classes/class-test-event.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/test/unit/php/includes/core/classes/class-test-event.php b/test/unit/php/includes/core/classes/class-test-event.php index 5866e9d9e..dbb455fcb 100644 --- a/test/unit/php/includes/core/classes/class-test-event.php +++ b/test/unit/php/includes/core/classes/class-test-event.php @@ -407,10 +407,14 @@ public function test_get_calendar_links(): void { $event->save_datetimes( $params ); $output = $event->get_calendar_links(); + + $expected_google_link = 'https://www.google.com/calendar/event?action=TEMPLATE&text=Unit+Test+Event&dates=20200511T150000Z%2F20200511T170000Z&details=' . urlencode($description) . '&location=Unit+Test+Venue%2C+123+Main+Street%2C+Montclair%2C+NJ+07042&sprop=name%3A'; + $expected_yahoo_link = 'https://calendar.yahoo.com/?v=60&view=d&type=20&title=Unit+Test+Event&st=20200511T150000Z&dur=0200&desc=' . urlencode($description) . '&in_loc=Unit+Test+Venue%2C+123+Main+Street%2C+Montclair%2C+NJ+07042'; + $expects = array( 'google' => array( 'name' => 'Google Calendar', - 'link' => 'https://www.google.com/calendar/event?action=TEMPLATE&text=Unit Test Event&dates=20200511T150000Z/20200511T170000Z&details=' . $description . '&location=Unit Test Venue, 123 Main Street, Montclair, NJ 07042&sprop=name:', + 'link' => $expected_google_link, ), 'ical' => array( 'name' => 'iCal', @@ -422,7 +426,7 @@ public function test_get_calendar_links(): void { ), 'yahoo' => array( 'name' => 'Yahoo Calendar', - 'link' => 'https://calendar.yahoo.com/?v=60&view=d&type=20&title=Unit Test Event&st=20200511T150000Z&dur=0200&desc=' . $description . '&in_loc=Unit Test Venue, 123 Main Street, Montclair, NJ 07042', + 'link' => $expected_yahoo_link, ), ); From f315f1b2cad0803676c5bc906d2ec452b5cf1acf Mon Sep 17 00:00:00 2001 From: Carsten Bach Date: Thu, 11 Jul 2024 19:06:36 +0200 Subject: [PATCH 4/5] Fix CS on unit test --- test/unit/php/includes/core/classes/class-test-event.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/unit/php/includes/core/classes/class-test-event.php b/test/unit/php/includes/core/classes/class-test-event.php index dbb455fcb..4385c75fe 100644 --- a/test/unit/php/includes/core/classes/class-test-event.php +++ b/test/unit/php/includes/core/classes/class-test-event.php @@ -406,10 +406,10 @@ public function test_get_calendar_links(): void { $event->save_datetimes( $params ); - $output = $event->get_calendar_links(); + $output = $event->get_calendar_links(); - $expected_google_link = 'https://www.google.com/calendar/event?action=TEMPLATE&text=Unit+Test+Event&dates=20200511T150000Z%2F20200511T170000Z&details=' . urlencode($description) . '&location=Unit+Test+Venue%2C+123+Main+Street%2C+Montclair%2C+NJ+07042&sprop=name%3A'; - $expected_yahoo_link = 'https://calendar.yahoo.com/?v=60&view=d&type=20&title=Unit+Test+Event&st=20200511T150000Z&dur=0200&desc=' . urlencode($description) . '&in_loc=Unit+Test+Venue%2C+123+Main+Street%2C+Montclair%2C+NJ+07042'; + $expected_google_link = 'https://www.google.com/calendar/event?action=TEMPLATE&text=Unit+Test+Event&dates=20200511T150000Z%2F20200511T170000Z&details=' . rawurlencode( $description ) . '&location=Unit+Test+Venue%2C+123+Main+Street%2C+Montclair%2C+NJ+07042&sprop=name%3A'; + $expected_yahoo_link = 'https://calendar.yahoo.com/?v=60&view=d&type=20&title=Unit+Test+Event&st=20200511T150000Z&dur=0200&desc=' . rawurlencode( $description ) . '&in_loc=Unit+Test+Venue%2C+123+Main+Street%2C+Montclair%2C+NJ+07042'; $expects = array( 'google' => array( From 9f44bc3d853cd59741a050b2079f853040816164 Mon Sep 17 00:00:00 2001 From: Carsten Bach Date: Thu, 11 Jul 2024 19:15:45 +0200 Subject: [PATCH 5/5] Use rawurlencode consequently --- includes/core/classes/class-event.php | 4 ++-- test/unit/php/includes/core/classes/class-test-event.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/core/classes/class-event.php b/includes/core/classes/class-event.php index c58dd70e5..0de4c76b2 100644 --- a/includes/core/classes/class-event.php +++ b/includes/core/classes/class-event.php @@ -497,7 +497,7 @@ protected function get_google_calendar_link(): string { ); return add_query_arg( - urlencode_deep( $params ), + rawurlencode_deep( $params ), 'https://www.google.com/calendar/event' ); } @@ -547,7 +547,7 @@ protected function get_yahoo_calendar_link(): string { ); return add_query_arg( - urlencode_deep( $params ), + rawurlencode_deep( $params ), 'https://calendar.yahoo.com/' ); } diff --git a/test/unit/php/includes/core/classes/class-test-event.php b/test/unit/php/includes/core/classes/class-test-event.php index 4385c75fe..0776232ca 100644 --- a/test/unit/php/includes/core/classes/class-test-event.php +++ b/test/unit/php/includes/core/classes/class-test-event.php @@ -408,8 +408,8 @@ public function test_get_calendar_links(): void { $output = $event->get_calendar_links(); - $expected_google_link = 'https://www.google.com/calendar/event?action=TEMPLATE&text=Unit+Test+Event&dates=20200511T150000Z%2F20200511T170000Z&details=' . rawurlencode( $description ) . '&location=Unit+Test+Venue%2C+123+Main+Street%2C+Montclair%2C+NJ+07042&sprop=name%3A'; - $expected_yahoo_link = 'https://calendar.yahoo.com/?v=60&view=d&type=20&title=Unit+Test+Event&st=20200511T150000Z&dur=0200&desc=' . rawurlencode( $description ) . '&in_loc=Unit+Test+Venue%2C+123+Main+Street%2C+Montclair%2C+NJ+07042'; + $expected_google_link = 'https://www.google.com/calendar/event?action=TEMPLATE&text=Unit%20Test%20Event&dates=20200511T150000Z%2F20200511T170000Z&details=' . rawurlencode( $description ) . '&location=Unit%20Test%20Venue%2C%20123%20Main%20Street%2C%20Montclair%2C%20NJ%2007042&sprop=name%3A'; + $expected_yahoo_link = 'https://calendar.yahoo.com/?v=60&view=d&type=20&title=Unit%20Test%20Event&st=20200511T150000Z&dur=0200&desc=' . rawurlencode( $description ) . '&in_loc=Unit%20Test%20Venue%2C%20123%20Main%20Street%2C%20Montclair%2C%20NJ%2007042'; $expects = array( 'google' => array(