Skip to content

Commit a818ed4

Browse files
committed
isBlockedId tests + bug fix in int regex
1 parent 9390a85 commit a818ed4

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Sqids.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,7 @@ protected function isBlockedId(string $id): bool
811811
if ($id == $word) {
812812
return true;
813813
}
814-
} elseif (preg_match('/~[0-9]+~/', (string) $word)) {
814+
} elseif (preg_match('/[0-9]+/', (string) $word)) {
815815
if (str_starts_with($id, (string) $word) || strrpos($id, (string) $word) === strlen($id) - strlen((string) $word)) {
816816
return true;
817817
}

tests/SqidsBlocklistTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,28 @@ public function testMaxEncodingAttempts()
106106
$this->expectException(InvalidArgumentException::class);
107107
$sqids->encode([0]);
108108
}
109+
110+
public function testSpecificIsBlockedIdScenarios()
111+
{
112+
$sqids = new Sqids('', 0, ['hey']);
113+
$this->assertSame('86u', $sqids->encode([100]));
114+
115+
$sqids = new Sqids('', 0, ['86u']);
116+
$this->assertSame('sec', $sqids->encode([100]));
117+
118+
$sqids = new Sqids('', 0, ['vFo']);
119+
$this->assertSame('gMvFo', $sqids->encode([1000000]));
120+
121+
$sqids = new Sqids('', 0, ['lP3i']);
122+
$this->assertSame('oDqljxrokxRt', $sqids->encode([100, 202, 303, 404]));
123+
124+
$sqids = new Sqids('', 0, ['1HkYs']);
125+
$this->assertSame('oDqljxrokxRt', $sqids->encode([100, 202, 303, 404]));
126+
127+
$sqids = new Sqids('', 0, ['0hfxX']);
128+
$this->assertSame('862REt0hfxXVdsLG8vGWD', $sqids->encode([101, 202, 303, 404, 505, 606, 707]));
129+
130+
$sqids = new Sqids('', 0, ['hfxX']);
131+
$this->assertSame('seu8n1jO9C4KQQDxdOxsK', $sqids->encode([101, 202, 303, 404, 505, 606, 707]));
132+
}
109133
}

0 commit comments

Comments
 (0)