Skip to content

Commit 6d957c6

Browse files
committed
Add usort to EndPointTrait::toAbsoluteEndpoint
Fixes #16
1 parent e791fa0 commit 6d957c6

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/Discord/EndpointTrait.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ public function toAbsoluteEndpoint(bool $onlyMajorParameters = false): string
7272
{
7373
$endpoint = $this->endpoint;
7474

75-
foreach ($this->vars as $var) {
75+
// Process in order of longest to shortest variable name to prevent partial replacements (see #16).
76+
$vars = $this->vars;
77+
usort($vars, function ($a, $b) {
78+
return strlen($b) <=> strlen($a);
79+
});
80+
81+
foreach ($vars as $var) {
7682
if (
7783
! isset($this->args[$var]) ||
7884
(

src/Discord/HttpTrait.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,7 @@ protected function checkunboundQueue(): void
416416
public static function isUnboundEndpoint(Request $request): bool
417417
{
418418
$url = $request->getUrl();
419+
419420
return
420421
(strpos($url, '/interactions') === 0 && strpos($url, '/callback') !== false)
421422
|| strpos($url, '/webhooks') === 0;

0 commit comments

Comments
 (0)