Skip to content
Myr

Additional fixes and tests for #508 (#509)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Additional fixes and tests for #508 I didn't fully understand the project and test structure, but while preparing the backport for v3 I gained a fuller understanding. The tests now exercise the customAlphabet code and the non-secure variant, and fix the infinite loop case in `customRandom` on both node and the browser. * `const` -> `let` * lint

authored by Kris Reeves · committed by GitHub · parent 313a14e · Browse files · 4 files+28 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+28 added−3 removed

  • tests:+26 added−1 removed
  • other:+2 added−2 removed

4 files+28 added−3 removed

modified:test/index.test.js+9 added
124 unmodified lines
125 let nanoidA = customAlphabet('a')126 equal(nanoidA(10), 'aaaaaaaaaa')127 })128129 test(`${type} / customAlphabet / avoids pool pollution, infinite loop`, () => {130 let ALPHABET = 'abcdefghijklmnopqrstuvwxyz'131 let nanoid2 = customAlphabet(ALPHABET)132 nanoid2(2.1)133 let second = nanoid2()134 let third = nanoid2()135 notEqual(second, third)136 })137138 test(`${type} / customRandom / supports generator`, () => {139 let sequence = [2, 255, 3, 7, 7, 7, 7, 7, 0, 1]140 function fakeRandom(size) {141 let bytes = []
74 unmodified lines
modified:test/non-secure.test.js+17 added-1 removed
modified:index.browser.js+1 added-1 removed
modified:index.js+1 added-1 removed
57 unmodified lines
58 let i = step59 while (i--) {60 // Adding `|| ''` refuses a random byte that exceeds the alphabet size.61 id += alphabet[bytes[i] & mask] || ''62 if (id.length === size) return id62 if (id.length >= size) return id63 }64 }65 }66}
20 unmodified lines