Skip to content

Commit 84d14d6

Browse files
authored
Merge pull request #101 from hildjj/nanPayloadsHaveSign
keepNanPayloads should look for a sign bit also
2 parents 8e3b457 + 6bf5291 commit 84d14d6

4 files changed

Lines changed: 16 additions & 18 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
"c8": "10.1.3",
8080
"cbor-edn": "0.2.2",
8181
"eslint": "9.39.2",
82-
"eslint-plugin-jsdoc": "62.4.0",
82+
"eslint-plugin-jsdoc": "62.4.1",
8383
"package-extract": "3.1.3",
8484
"rimraf": "^6.1.2",
8585
"tsup": "8.5.1",

pnpm-lock.yaml

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

src/container.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ export class CBORcontainer {
228228
throw new Error(`Invalid NaN encoding: "${u8toHex(buf)}"`);
229229
}
230230
} else if (opts.keepNanPayloads) {
231-
if (val.payload) {
231+
if (val.payload || val.sign === -1) {
232232
if (opts.rejectLongFloats && !val.isShortestEncoding) {
233233
throw new Error(`NaN should have been encoded shorter: ${value}`);
234234
}

test/decoder.test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import '../lib/types.js';
22
import * as cases from './cases.js';
33
import {CBORcontainer} from '../lib/container.js';
4+
import {NAN} from '../lib/float.js';
45
import {TAG} from '../lib/constants.js';
56
import {Tag} from '../lib/tag.js';
67
import assert from 'node:assert/strict';
@@ -235,6 +236,9 @@ test('ignoreGlobalTags', () => {
235236
});
236237

237238
test('keep nan payloads', () => {
239+
testAll([
240+
[new NAN(-0), '', 'f9fe00'],
241+
], {keepNanPayloads: true});
238242
failAll([
239243
'0xFB7FF1000000000000',
240244
], {rejectLongFloats: true, keepNanPayloads: true});

0 commit comments

Comments
 (0)