Skip to content

Commit

Permalink
feat: use wfAppendQuery to apply query to URL instead of sprintf
Browse files Browse the repository at this point in the history
This is a safer method and also avoid the issue where the URL has conflicting question mark
  • Loading branch information
alistair3149 committed Jul 12, 2024
1 parent 3a3a62a commit f84c125
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion includes/EmbedService/AbstractEmbedService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion includes/EmbedService/Bandcamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion includes/EmbedService/Bilibili.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down
2 changes: 1 addition & 1 deletion includes/EmbedService/Twitch/Twitch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

/**
Expand Down

0 comments on commit f84c125

Please sign in to comment.