Skip to content

Commit dbe6b14

Browse files
authored
fix(broadcaster): incorrect channel matching because of dot in pattern (#54303)
* fix(broadcaster): incorrect channel matching because of dot in pattern * refactor(broadcaster): update according to styleci
1 parent 6e0e2cb commit dbe6b14

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

src/Illuminate/Broadcasting/Broadcasters/Broadcaster.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,8 @@ protected function retrieveChannelOptions($channel)
372372
*/
373373
protected function channelNameMatchesPattern($channel, $pattern)
374374
{
375+
$pattern = str_replace('.', '\.', $pattern);
376+
375377
return preg_match('/^'.preg_replace('/\{(.*?)\}/', '([^\.]+)', $pattern).'$/', $channel);
376378
}
377379

tests/Broadcasting/UsePusherChannelsNamesTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,19 @@ public function testChannelNameNormalizationSpecialCase()
3030
);
3131
}
3232

33+
public function testChannelNamePatternMatching()
34+
{
35+
$broadcaster = new FakeBroadcasterUsingPusherChannelsNames;
36+
37+
$this->assertEquals(
38+
0,
39+
$broadcaster->testChannelNameMatchesPattern(
40+
'TestChannel',
41+
'Test.{id}'
42+
)
43+
);
44+
}
45+
3346
#[DataProvider('channelsProvider')]
3447
public function testIsGuardedChannel($requestChannelName, $_, $guarded)
3548
{
@@ -103,4 +116,9 @@ public function broadcast(array $channels, $event, array $payload = [])
103116
{
104117
//
105118
}
119+
120+
public function testChannelNameMatchesPattern($channel, $pattern)
121+
{
122+
return $this->channelNameMatchesPattern($channel, $pattern);
123+
}
106124
}

0 commit comments

Comments
 (0)