Skip to content

Commit

Permalink
Merge pull request #40 from M-Scott-Lassiter/next
Browse files Browse the repository at this point in the history
Add additional error handling for bad dictionary inputs
  • Loading branch information
M-Scott-Lassiter committed May 14, 2022
2 parents 12ac33c + 3f37616 commit 31f12ea
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
## [1.5.0](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/compare/v1.4.0...v1.5.0) (2022-05-03)


### :gift: Feature Changes

* add the `deconstruct` function to the class ([5df23ec](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/5df23ec35290a2cbf7d4c95038af359fd0bf55b5)), closes [#37](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/37)

- add the `deconstruct` function to the class ([5df23ec](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/5df23ec35290a2cbf7d4c95038af359fd0bf55b5)), closes [#37](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/37)

### :dart: Test Changes

* add test cases for the `deconstruct` function ([1eafa19](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/1eafa19b487e7db8697e18fda6847194028eab48)), closes [#37](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/37)
- add test cases for the `deconstruct` function ([1eafa19](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/commit/1eafa19b487e7db8697e18fda6847194028eab48)), closes [#37](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/issues/37)

## [1.4.0](https://github.com/M-Scott-Lassiter/Alphanumeric-Encoder/compare/v1.3.0...v1.4.0) (2022-05-02)

Expand Down
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,15 @@ class AlphanumericEncoder {
*/
set dictionary(newDictionary) {
// Check for empty dictionaries
if (newDictionary === null || newDictionary === undefined || newDictionary.length === 0) {
throw new RangeError('The dictionary cannot be null, undefined, or an empty string.')
if (
typeof newDictionary !== 'string' ||
newDictionary.length === 0 ||
// eslint-disable-next-line no-self-compare
newDictionary !== newDictionary // This verifies it wasn't passed NaN
) {
throw new RangeError(
'The dictionary cannot be null, undefined, boolean, NaN, or an empty string.'
)
}

// Check for invalid characters. Using a regular expression, make sure only letters and numbers are allowed.
Expand Down
12 changes: 12 additions & 0 deletions index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ describe('Dictionary Validation', () => {
}).toThrow(/undefined/)
})

test.each([true, false])('Dictionary cannot be boolean %p', (input) => {
expect(() => {
encoder.dictionary = input
}).toThrow(/boolean/)
})

test('Dictionary cannot be NaN', () => {
expect(() => {
encoder.dictionary = NaN
}).toThrow(/NaN/)
})

describe('Valid Dictionaries (no lower case)', () => {
setupNewEncoderForTesting()

Expand Down

0 comments on commit 31f12ea

Please sign in to comment.