From f84c12510d0c03f448d652e815ee8abef1c56051 Mon Sep 17 00:00:00 2001 From: alistair3149 Date: Fri, 12 Jul 2024 16:46:36 -0400 Subject: [PATCH] feat: use wfAppendQuery to apply query to URL instead of sprintf This is a safer method and also avoid the issue where the URL has conflicting question mark --- includes/EmbedService/AbstractEmbedService.php | 2 +- includes/EmbedService/Bandcamp.php | 2 +- includes/EmbedService/Bilibili.php | 2 +- includes/EmbedService/Twitch/Twitch.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/EmbedService/AbstractEmbedService.php b/includes/EmbedService/AbstractEmbedService.php index 06e7205..f264484 100644 --- a/includes/EmbedService/AbstractEmbedService.php +++ b/includes/EmbedService/AbstractEmbedService.php @@ -261,7 +261,7 @@ protected function getIdRegex(): array { */ public function getUrl(): string { if ( $this->getUrlArgs() !== false ) { - return sprintf( '%s?%s', sprintf( $this->getBaseUrl(), $this->getId() ), $this->getUrlArgs() ); + return wfAppendQuery( sprintf( $this->getBaseUrl(), $this->getId() ), $this->getUrlArgs() ); } return sprintf( $this->getBaseUrl(), $this->getId() ); diff --git a/includes/EmbedService/Bandcamp.php b/includes/EmbedService/Bandcamp.php index 4a9e978..01cc8d6 100644 --- a/includes/EmbedService/Bandcamp.php +++ b/includes/EmbedService/Bandcamp.php @@ -40,7 +40,7 @@ public function getUrl(): string { unset( $this->urlArgs['autoplay'] ); $args = array_shift( $this->urlArgs ); - return sprintf( '%s&%s', sprintf( $this->getBaseUrl(), $this->getId() ), $args ?? '' ); + return wfAppendQuery( sprintf( $this->getBaseUrl(), $this->getId() ), $args ?? '' ); } return parent::getUrl(); diff --git a/includes/EmbedService/Bilibili.php b/includes/EmbedService/Bilibili.php index f051095..888a72f 100644 --- a/includes/EmbedService/Bilibili.php +++ b/includes/EmbedService/Bilibili.php @@ -53,7 +53,7 @@ public function getCSPUrls(): array { */ public function getUrl(): string { if ( $this->getUrlArgs() !== false ) { - return sprintf( '%s&%s', sprintf( $this->getBaseUrl(), $this->getId() ), $this->getUrlArgs() ); + return wfAppendQuery( sprintf( $this->getBaseUrl(), $this->getId() ), $this->getUrlArgs() ); } return sprintf( $this->getBaseUrl(), $this->getId() ); diff --git a/includes/EmbedService/Twitch/Twitch.php b/includes/EmbedService/Twitch/Twitch.php index 8c92311..f6f49d5 100644 --- a/includes/EmbedService/Twitch/Twitch.php +++ b/includes/EmbedService/Twitch/Twitch.php @@ -73,7 +73,7 @@ public function getUrl(): string { $urlArgs = http_build_query( $parsedArgs ); } - return sprintf( '%s&%s', sprintf( $this->getBaseUrl(), $this->getId() ), $urlArgs ); + return wfAppendQuery( sprintf( $this->getBaseUrl(), $this->getId() ), $urlArgs ); } /**