Skip to content

Commit 8594bc6

Browse files
authored
Throw when oid is not an integer (Fix #128) (#129)
1 parent 05badcd commit 8594bc6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ function setTypeParser (oid, format, parseFn) {
3333
parseFn = format
3434
format = 'text'
3535
}
36+
if (!Number.isInteger(oid)) {
37+
throw new TypeError('oid must be an integer: ' + oid)
38+
}
3639
typeParsers[format][oid] = parseFn
3740
};
3841

test/index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
const test = require('tape')
3-
const getTypeParser = require('../').getTypeParser
3+
const { getTypeParser, setTypeParser } = require('../')
44
const types = require('./types')
55

66
test('types', function (t) {
@@ -64,4 +64,14 @@ test('types', function (t) {
6464
t.equal(correct, 300)
6565
t.end()
6666
})
67+
68+
t.test('setTypeParser should throw when oid is not an integer', function (t) {
69+
t.throws(function () {
70+
setTypeParser(null, function () {})
71+
}, /^TypeError: oid must be an integer/)
72+
t.throws(function () {
73+
setTypeParser('a', function () {})
74+
}, /^TypeError: oid must be an integer/)
75+
t.end()
76+
})
6777
})

0 commit comments

Comments
 (0)