Skip to content

Commit

Permalink
fix(broadcaster): incorrect channel matching because of dot in pattern (
Browse files Browse the repository at this point in the history
#54303)

* fix(broadcaster): incorrect channel matching because of dot in pattern

* refactor(broadcaster): update according to styleci
  • Loading branch information
021-projects authored Jan 22, 2025
1 parent 6e0e2cb commit dbe6b14
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,8 @@ protected function retrieveChannelOptions($channel)
*/
protected function channelNameMatchesPattern($channel, $pattern)
{
$pattern = str_replace('.', '\.', $pattern);

return preg_match('/^'.preg_replace('/\{(.*?)\}/', '([^\.]+)', $pattern).'$/', $channel);
}

Expand Down
18 changes: 18 additions & 0 deletions tests/Broadcasting/UsePusherChannelsNamesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,19 @@ public function testChannelNameNormalizationSpecialCase()
);
}

public function testChannelNamePatternMatching()
{
$broadcaster = new FakeBroadcasterUsingPusherChannelsNames;

$this->assertEquals(
0,
$broadcaster->testChannelNameMatchesPattern(
'TestChannel',
'Test.{id}'
)
);
}

#[DataProvider('channelsProvider')]
public function testIsGuardedChannel($requestChannelName, $_, $guarded)
{
Expand Down Expand Up @@ -103,4 +116,9 @@ public function broadcast(array $channels, $event, array $payload = [])
{
//
}

public function testChannelNameMatchesPattern($channel, $pattern)
{
return $this->channelNameMatchesPattern($channel, $pattern);
}
}

0 comments on commit dbe6b14

Please sign in to comment.