Skip to content

Commit 8103161

Browse files
committed
fix: spec update - blocklist filtering in uppercase-only alphabet
1 parent a034f37 commit 8103161

File tree

8 files changed

+1291
-1079
lines changed

8 files changed

+1291
-1079
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
**v0.1.3:**
4+
- Bug fix: spec update: blocklist filtering in uppercase-only alphabet [[PR #7](https://github.com/sqids/sqids-spec/pull/7)]
5+
- Dev dependencies updated
6+
37
**v0.1.2:**
48
- Bug fix: cjs import error [[PR #5](https://github.com/sqids/sqids-javascript/pull/5)]
59

cjs/sqids.js

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/sqids.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esm/sqids.js

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sqids",
3-
"version": "0.1.2",
3+
"version": "0.1.3",
44
"description": "Generate YouTube-like ids from numbers.",
55
"keywords": [
66
"sqids",
@@ -80,7 +80,7 @@
8080
"not dead"
8181
],
8282
"devDependencies": {
83-
"@niieani/scaffold": "^1.7.3",
83+
"@niieani/scaffold": "^1.7.8",
8484
"nodemark": "^0.3.0",
8585
"require-from-web": "^1.2.0",
8686
"ts-node": "^10.9.1"

src/sqids.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,14 @@ export default class Sqids {
604604
}
605605

606606
const filteredBlocklist = new Set<string>()
607-
const alphabetChars = alphabet.split('')
607+
const alphabetChars = alphabet.toLowerCase().split('')
608608
for (const word of blocklist) {
609609
if (word.length >= 3) {
610-
const wordChars = word.split('')
610+
const wordLowercased = word.toLowerCase()
611+
const wordChars = wordLowercased.split('')
611612
const intersection = wordChars.filter((c) => alphabetChars.includes(c))
612613
if (intersection.length === wordChars.length) {
613-
filteredBlocklist.add(word.toLowerCase())
614+
filteredBlocklist.add(wordLowercased)
614615
}
615616
}
616617
}

src/tests/blocklist.test.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,17 @@ describe('blocklist', () => {
7474

7575
expect(sqids.decode(sqids.encode([1_000]))).toEqual([1_000])
7676
})
77+
78+
it('blocklist filtering in constructor', () => {
79+
const sqids = new Sqids({
80+
alphabet: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
81+
blocklist: new Set(['sqnmpn']), // lowercase blocklist in only-uppercase alphabet
82+
})
83+
84+
const id = sqids.encode([1, 2, 3])
85+
const numbers = sqids.decode(id)
86+
87+
expect(id).toBe('ULPBZGBM') // without blocklist, would've been "SQNMPN"
88+
expect(numbers).toEqual([1, 2, 3])
89+
})
7790
})

0 commit comments

Comments
 (0)